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
39dadf7a
Kaydet (Commit)
39dadf7a
authored
Mar 20, 2015
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue 23705: Improve the performance of __contains__ checks for deques.
üst
17d3a58e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
1 deletion
+53
-1
test_deque.py
Lib/test/test_deque.py
+20
-0
_collectionsmodule.c
Modules/_collectionsmodule.c
+33
-1
No files found.
Lib/test/test_deque.py
Dosyayı görüntüle @
39dadf7a
...
...
@@ -164,6 +164,26 @@ class TestBasic(unittest.TestCase):
self
.
assertEqual
(
x
>
y
,
list
(
x
)
>
list
(
y
),
(
x
,
y
))
self
.
assertEqual
(
x
>=
y
,
list
(
x
)
>=
list
(
y
),
(
x
,
y
))
def
test_contains
(
self
):
n
=
200
d
=
deque
(
range
(
n
))
for
i
in
range
(
n
):
self
.
assertTrue
(
i
in
d
)
self
.
assertTrue
((
n
+
1
)
not
in
d
)
# Test detection of mutation during iteration
d
=
deque
(
range
(
n
))
d
[
n
//
2
]
=
MutateCmp
(
d
,
False
)
with
self
.
assertRaises
(
RuntimeError
):
n
in
d
# Test detection of comparison exceptions
d
=
deque
(
range
(
n
))
d
[
n
//
2
]
=
BadCmp
()
with
self
.
assertRaises
(
RuntimeError
):
n
in
d
def
test_extend
(
self
):
d
=
deque
(
'a'
)
self
.
assertRaises
(
TypeError
,
d
.
extend
,
1
)
...
...
Modules/_collectionsmodule.c
Dosyayı görüntüle @
39dadf7a
...
...
@@ -724,6 +724,38 @@ deque_count(dequeobject *deque, PyObject *v)
PyDoc_STRVAR
(
count_doc
,
"D.count(value) -> integer -- return number of occurrences of value"
);
static
int
deque_contains
(
dequeobject
*
deque
,
PyObject
*
v
)
{
block
*
b
=
deque
->
leftblock
;
Py_ssize_t
index
=
deque
->
leftindex
;
Py_ssize_t
n
=
Py_SIZE
(
deque
);
Py_ssize_t
i
;
size_t
start_state
=
deque
->
state
;
PyObject
*
item
;
int
cmp
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
CHECK_NOT_END
(
b
);
item
=
b
->
data
[
index
];
cmp
=
PyObject_RichCompareBool
(
item
,
v
,
Py_EQ
);
if
(
cmp
)
{
return
cmp
;
}
if
(
start_state
!=
deque
->
state
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
"deque mutated during iteration"
);
return
-
1
;
}
index
++
;
if
(
index
==
BLOCKLEN
)
{
b
=
b
->
rightlink
;
index
=
0
;
}
}
return
0
;
}
static
Py_ssize_t
deque_len
(
dequeobject
*
deque
)
{
...
...
@@ -1154,7 +1186,7 @@ static PySequenceMethods deque_as_sequence = {
0
,
/* sq_slice */
(
ssizeobjargproc
)
deque_ass_item
,
/* sq_ass_item */
0
,
/* sq_ass_slice */
0
,
/* sq_contains */
(
objobjproc
)
deque_contains
,
/* sq_contains */
(
binaryfunc
)
deque_inplace_concat
,
/* sq_inplace_concat */
0
,
/* sq_inplace_repeat */
...
...
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