Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
2d53bed7
Unverified
Kaydet (Commit)
2d53bed7
authored
Ock 07, 2019
tarafından
Raymond Hettinger
Kaydeden (comit)
GitHub
Ock 07, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-35664: Optimize operator.itemgetter (GH-11435)
üst
3f7983a2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
5 deletions
+54
-5
test_operator.py
Lib/test/test_operator.py
+13
-0
2019-01-04-22-18-25.bpo-35664.Z-Gyyj.rst
...S.d/next/Library/2019-01-04-22-18-25.bpo-35664.Z-Gyyj.rst
+4
-0
_operator.c
Modules/_operator.c
+37
-5
No files found.
Lib/test/test_operator.py
Dosyayı görüntüle @
2d53bed7
...
...
@@ -401,6 +401,19 @@ class OperatorTestCase:
self
.
assertEqual
(
operator
.
itemgetter
(
2
,
10
,
5
)(
data
),
(
'2'
,
'10'
,
'5'
))
self
.
assertRaises
(
TypeError
,
operator
.
itemgetter
(
2
,
'x'
,
5
),
data
)
# interesting indices
t
=
tuple
(
'abcde'
)
self
.
assertEqual
(
operator
.
itemgetter
(
-
1
)(
t
),
'e'
)
self
.
assertEqual
(
operator
.
itemgetter
(
slice
(
2
,
4
))(
t
),
(
'c'
,
'd'
))
# interesting sequences
class
T
(
tuple
):
'Tuple subclass'
pass
self
.
assertEqual
(
operator
.
itemgetter
(
0
)(
T
(
'abc'
)),
'a'
)
self
.
assertEqual
(
operator
.
itemgetter
(
0
)([
'a'
,
'b'
,
'c'
]),
'a'
)
self
.
assertEqual
(
operator
.
itemgetter
(
0
)(
range
(
100
,
200
)),
100
)
def
test_methodcaller
(
self
):
operator
=
self
.
module
self
.
assertRaises
(
TypeError
,
operator
.
methodcaller
)
...
...
Misc/NEWS.d/next/Library/2019-01-04-22-18-25.bpo-35664.Z-Gyyj.rst
0 → 100644
Dosyayı görüntüle @
2d53bed7
Improve operator.itemgetter() performance by 33% with optimized argument
handling and with adding a fast path for the common case of a single
non-negative integer index into a tuple (which is the typical use case in
the standard library).
Modules/_operator.c
Dosyayı görüntüle @
2d53bed7
...
...
@@ -937,6 +937,7 @@ typedef struct {
PyObject_HEAD
Py_ssize_t
nitems
;
PyObject
*
item
;
Py_ssize_t
index
;
// -1 unless *item* is a single non-negative integer index
}
itemgetterobject
;
static
PyTypeObject
itemgetter_type
;
...
...
@@ -948,6 +949,7 @@ itemgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
itemgetterobject
*
ig
;
PyObject
*
item
;
Py_ssize_t
nitems
;
Py_ssize_t
index
;
if
(
!
_PyArg_NoKeywords
(
"itemgetter"
,
kwds
))
return
NULL
;
...
...
@@ -967,6 +969,21 @@ itemgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_INCREF
(
item
);
ig
->
item
=
item
;
ig
->
nitems
=
nitems
;
ig
->
index
=
-
1
;
if
(
PyLong_CheckExact
(
item
))
{
index
=
PyLong_AsSsize_t
(
item
);
if
(
index
<
0
)
{
/* If we get here, then either the index conversion failed
* due to being out of range, or the index was a negative
* integer. Either way, we clear any possible exception
* and fall back to the slow path, where ig->index is -1.
*/
PyErr_Clear
();
}
else
{
ig
->
index
=
index
;
}
}
PyObject_GC_Track
(
ig
);
return
(
PyObject
*
)
ig
;
...
...
@@ -993,12 +1010,27 @@ itemgetter_call(itemgetterobject *ig, PyObject *args, PyObject *kw)
PyObject
*
obj
,
*
result
;
Py_ssize_t
i
,
nitems
=
ig
->
nitems
;
if
(
!
_PyArg_NoKeywords
(
"itemgetter"
,
kw
))
return
NULL
;
if
(
!
PyArg_UnpackTuple
(
args
,
"itemgetter"
,
1
,
1
,
&
obj
))
return
NULL
;
if
(
nitems
==
1
)
assert
(
PyTuple_CheckExact
(
args
));
if
(
kw
==
NULL
&&
PyTuple_GET_SIZE
(
args
)
==
1
)
{
obj
=
PyTuple_GET_ITEM
(
args
,
0
);
}
else
{
if
(
!
_PyArg_NoKeywords
(
"itemgetter"
,
kw
))
return
NULL
;
if
(
!
PyArg_UnpackTuple
(
args
,
"itemgetter"
,
1
,
1
,
&
obj
))
return
NULL
;
}
if
(
nitems
==
1
)
{
if
(
ig
->
index
>=
0
&&
PyTuple_CheckExact
(
obj
)
&&
ig
->
index
<
PyTuple_GET_SIZE
(
obj
))
{
result
=
PyTuple_GET_ITEM
(
obj
,
ig
->
index
);
Py_INCREF
(
result
);
return
result
;
}
return
PyObject_GetItem
(
obj
,
ig
->
item
);
}
assert
(
PyTuple_Check
(
ig
->
item
));
assert
(
PyTuple_GET_SIZE
(
ig
->
item
)
==
nitems
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment