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
060c7f6b
Kaydet (Commit)
060c7f6b
authored
Mar 10, 2009
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Small optimization for corner case where maxlen==0.
üst
2cf03a82
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
1 deletion
+41
-1
test_deque.py
Lib/test/test_deque.py
+18
-1
_collectionsmodule.c
Modules/_collectionsmodule.c
+23
-0
No files found.
Lib/test/test_deque.py
Dosyayı görüntüle @
060c7f6b
...
@@ -51,7 +51,9 @@ class TestBasic(unittest.TestCase):
...
@@ -51,7 +51,9 @@ class TestBasic(unittest.TestCase):
def
test_maxlen
(
self
):
def
test_maxlen
(
self
):
self
.
assertRaises
(
ValueError
,
deque
,
'abc'
,
-
1
)
self
.
assertRaises
(
ValueError
,
deque
,
'abc'
,
-
1
)
self
.
assertRaises
(
ValueError
,
deque
,
'abc'
,
-
2
)
self
.
assertRaises
(
ValueError
,
deque
,
'abc'
,
-
2
)
d
=
deque
(
range
(
10
),
maxlen
=
3
)
it
=
iter
(
range
(
10
))
d
=
deque
(
it
,
maxlen
=
3
)
self
.
assertEqual
(
list
(
it
),
[])
self
.
assertEqual
(
repr
(
d
),
'deque([7, 8, 9], maxlen=3)'
)
self
.
assertEqual
(
repr
(
d
),
'deque([7, 8, 9], maxlen=3)'
)
self
.
assertEqual
(
list
(
d
),
[
7
,
8
,
9
])
self
.
assertEqual
(
list
(
d
),
[
7
,
8
,
9
])
self
.
assertEqual
(
d
,
deque
(
range
(
10
),
3
))
self
.
assertEqual
(
d
,
deque
(
range
(
10
),
3
))
...
@@ -88,6 +90,21 @@ class TestBasic(unittest.TestCase):
...
@@ -88,6 +90,21 @@ class TestBasic(unittest.TestCase):
fo
.
close
()
fo
.
close
()
support
.
unlink
(
support
.
TESTFN
)
support
.
unlink
(
support
.
TESTFN
)
def
test_maxlen_zero
(
self
):
it
=
iter
(
range
(
100
))
deque
(
it
,
maxlen
=
0
)
self
.
assertEqual
(
list
(
it
),
[])
it
=
iter
(
range
(
100
))
d
=
deque
(
maxlen
=
0
)
d
.
extend
(
it
)
self
.
assertEqual
(
list
(
it
),
[])
it
=
iter
(
range
(
100
))
d
=
deque
(
maxlen
=
0
)
d
.
extendleft
(
it
)
self
.
assertEqual
(
list
(
it
),
[])
def
test_comparisons
(
self
):
def
test_comparisons
(
self
):
d
=
deque
(
'xabc'
);
d
.
popleft
()
d
=
deque
(
'xabc'
);
d
.
popleft
()
for
e
in
[
d
,
deque
(
'abc'
),
deque
(
'ab'
),
deque
(),
list
(
d
)]:
for
e
in
[
d
,
deque
(
'abc'
),
deque
(
'ab'
),
deque
(),
list
(
d
)]:
...
...
Modules/_collectionsmodule.c
Dosyayı görüntüle @
060c7f6b
...
@@ -276,6 +276,23 @@ deque_appendleft(dequeobject *deque, PyObject *item)
...
@@ -276,6 +276,23 @@ deque_appendleft(dequeobject *deque, PyObject *item)
PyDoc_STRVAR
(
appendleft_doc
,
"Add an element to the left side of the deque."
);
PyDoc_STRVAR
(
appendleft_doc
,
"Add an element to the left side of the deque."
);
/* Run an iterator to exhaustion. Shortcut for
the extend/extendleft methods when maxlen == 0. */
static
PyObject
*
consume_iterator
(
PyObject
*
it
)
{
PyObject
*
item
;
while
((
item
=
PyIter_Next
(
it
))
!=
NULL
)
{
Py_DECREF
(
item
);
}
Py_DECREF
(
it
);
if
(
PyErr_Occurred
())
return
NULL
;
Py_RETURN_NONE
;
}
static
PyObject
*
static
PyObject
*
deque_extend
(
dequeobject
*
deque
,
PyObject
*
iterable
)
deque_extend
(
dequeobject
*
deque
,
PyObject
*
iterable
)
{
{
...
@@ -285,6 +302,9 @@ deque_extend(dequeobject *deque, PyObject *iterable)
...
@@ -285,6 +302,9 @@ deque_extend(dequeobject *deque, PyObject *iterable)
if
(
it
==
NULL
)
if
(
it
==
NULL
)
return
NULL
;
return
NULL
;
if
(
deque
->
maxlen
==
0
)
return
consume_iterator
(
it
);
while
((
item
=
PyIter_Next
(
it
))
!=
NULL
)
{
while
((
item
=
PyIter_Next
(
it
))
!=
NULL
)
{
deque
->
state
++
;
deque
->
state
++
;
if
(
deque
->
rightindex
==
BLOCKLEN
-
1
)
{
if
(
deque
->
rightindex
==
BLOCKLEN
-
1
)
{
...
@@ -323,6 +343,9 @@ deque_extendleft(dequeobject *deque, PyObject *iterable)
...
@@ -323,6 +343,9 @@ deque_extendleft(dequeobject *deque, PyObject *iterable)
if
(
it
==
NULL
)
if
(
it
==
NULL
)
return
NULL
;
return
NULL
;
if
(
deque
->
maxlen
==
0
)
return
consume_iterator
(
it
);
while
((
item
=
PyIter_Next
(
it
))
!=
NULL
)
{
while
((
item
=
PyIter_Next
(
it
))
!=
NULL
)
{
deque
->
state
++
;
deque
->
state
++
;
if
(
deque
->
leftindex
==
0
)
{
if
(
deque
->
leftindex
==
0
)
{
...
...
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