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
ca3788c2
Kaydet (Commit)
ca3788c2
authored
Agu 16, 2015
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #24874: Speed-up itertools and make it pickles more compact.
üst
a6a2d44d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
21 deletions
+44
-21
NEWS
Misc/NEWS
+3
-0
itertoolsmodule.c
Modules/itertoolsmodule.c
+41
-21
No files found.
Misc/NEWS
Dosyayı görüntüle @
ca3788c2
...
...
@@ -25,6 +25,9 @@ Library
-
Issue
#
21159
:
Improve
message
in
configparser
.
InterpolationMissingOptionError
.
Patch
from
Ł
ukasz
Langa
.
-
Issue
#
24874
:
Improve
speed
of
itertools
.
cycle
()
and
make
its
pickle
more
compact
.
-
Fix
crash
in
itertools
.
cycle
.
__setstate__
()
when
the
first
argument
wasn
't
a list.
...
...
Modules/itertoolsmodule.c
Dosyayı görüntüle @
ca3788c2
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
...
...
@@ -863,6 +865,7 @@ typedef struct {
PyObject_HEAD
PyObject
*
it
;
PyObject
*
saved
;
Py_ssize_t
index
;
int
firstpass
;
}
cycleobject
;
...
...
@@ -902,6 +905,7 @@ cycle_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
lz
->
it
=
it
;
lz
->
saved
=
saved
;
lz
->
index
=
0
;
lz
->
firstpass
=
0
;
return
(
PyObject
*
)
lz
;
...
...
@@ -911,15 +915,16 @@ static void
cycle_dealloc
(
cycleobject
*
lz
)
{
PyObject_GC_UnTrack
(
lz
);
Py_XDECREF
(
lz
->
saved
);
Py_XDECREF
(
lz
->
it
);
Py_XDECREF
(
lz
->
saved
);
Py_TYPE
(
lz
)
->
tp_free
(
lz
);
}
static
int
cycle_traverse
(
cycleobject
*
lz
,
visitproc
visit
,
void
*
arg
)
{
Py_VISIT
(
lz
->
it
);
if
(
lz
->
it
)
Py_VISIT
(
lz
->
it
);
Py_VISIT
(
lz
->
saved
);
return
0
;
}
...
...
@@ -928,13 +933,13 @@ static PyObject *
cycle_next
(
cycleobject
*
lz
)
{
PyObject
*
item
;
PyObject
*
it
;
PyObject
*
tmp
;
while
(
1
)
{
if
(
lz
->
it
!=
NULL
)
{
item
=
PyIter_Next
(
lz
->
it
);
if
(
item
!=
NULL
)
{
if
(
!
lz
->
firstpass
&&
PyList_Append
(
lz
->
saved
,
item
))
{
if
(
lz
->
firstpass
)
return
item
;
if
(
PyList_Append
(
lz
->
saved
,
item
))
{
Py_DECREF
(
item
);
return
NULL
;
}
...
...
@@ -942,27 +947,41 @@ cycle_next(cycleobject *lz)
}
/* Note: StopIteration is already cleared by PyIter_Next() */
if
(
PyErr_Occurred
())
return
NULL
;
if
(
PyList_Size
(
lz
->
saved
)
==
0
)
return
NULL
;
it
=
PyObject_GetIter
(
lz
->
saved
);
if
(
it
==
NULL
)
return
NULL
;
tmp
=
lz
->
it
;
lz
->
it
=
it
;
lz
->
firstpass
=
1
;
Py_DECREF
(
tmp
);
Py_CLEAR
(
lz
->
it
);
}
if
(
Py_SIZE
(
lz
->
saved
)
==
0
)
return
NULL
;
item
=
PyList_GET_ITEM
(
lz
->
saved
,
lz
->
index
);
lz
->
index
++
;
if
(
lz
->
index
>=
Py_SIZE
(
lz
->
saved
))
lz
->
index
=
0
;
Py_INCREF
(
item
);
return
item
;
}
static
PyObject
*
cycle_reduce
(
cycleobject
*
lz
)
{
/* Create a new cycle with the iterator tuple, then set
* the saved state on it.
*/
return
Py_BuildValue
(
"O(O)(Oi)"
,
Py_TYPE
(
lz
),
lz
->
it
,
lz
->
saved
,
lz
->
firstpass
);
/* Create a new cycle with the iterator tuple, then set the saved state */
if
(
lz
->
it
==
NULL
)
{
PyObject
*
it
=
PyObject_GetIter
(
lz
->
saved
);
if
(
it
==
NULL
)
return
NULL
;
if
(
lz
->
index
!=
0
)
{
_Py_IDENTIFIER
(
__setstate__
);
PyObject
*
res
=
_PyObject_CallMethodId
(
it
,
&
PyId___setstate__
,
"n"
,
lz
->
index
);
if
(
res
==
NULL
)
{
Py_DECREF
(
it
);
return
NULL
;
}
Py_DECREF
(
res
);
}
return
Py_BuildValue
(
"O(N)(Oi)"
,
Py_TYPE
(
lz
),
it
,
lz
->
saved
,
1
);
}
return
Py_BuildValue
(
"O(O)(Oi)"
,
Py_TYPE
(
lz
),
lz
->
it
,
lz
->
saved
,
lz
->
firstpass
);
}
static
PyObject
*
...
...
@@ -972,10 +991,11 @@ cycle_setstate(cycleobject *lz, PyObject *state)
int
firstpass
;
if
(
!
PyArg_ParseTuple
(
state
,
"O!i"
,
&
PyList_Type
,
&
saved
,
&
firstpass
))
return
NULL
;
Py_INCREF
(
saved
);
Py_CLEAR
(
lz
->
saved
);
lz
->
saved
=
saved
;
Py_XINCREF
(
lz
->
saved
);
lz
->
firstpass
=
firstpass
!=
0
;
lz
->
index
=
0
;
Py_RETURN_NONE
;
}
...
...
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