Kaydet (Commit) 0faa1ca5 authored tarafından Raymond Hettinger's avatar Raymond Hettinger

Speedup the inner loops for dropwhile(), islice(), ifilter(), and

ifilterfalse().
üst bdda9f38
...@@ -835,10 +835,12 @@ dropwhile_next(dropwhileobject *lz) ...@@ -835,10 +835,12 @@ dropwhile_next(dropwhileobject *lz)
PyObject *item, *good; PyObject *item, *good;
PyObject *it = lz->it; PyObject *it = lz->it;
long ok; long ok;
PyObject *(*iternext)(PyObject *);
for (;;) {
assert(PyIter_Check(it)); assert(PyIter_Check(it));
item = (*it->ob_type->tp_iternext)(it); iternext = *it->ob_type->tp_iternext;
for (;;) {
item = iternext(it);
if (item == NULL) if (item == NULL)
return NULL; return NULL;
if (lz->start == 1) if (lz->start == 1)
...@@ -1170,10 +1172,12 @@ islice_next(isliceobject *lz) ...@@ -1170,10 +1172,12 @@ islice_next(isliceobject *lz)
PyObject *item; PyObject *item;
PyObject *it = lz->it; PyObject *it = lz->it;
long oldnext; long oldnext;
PyObject *(*iternext)(PyObject *);
while (lz->cnt < lz->next) {
assert(PyIter_Check(it)); assert(PyIter_Check(it));
item = (*it->ob_type->tp_iternext)(it); iternext = *it->ob_type->tp_iternext;
while (lz->cnt < lz->next) {
item = iternext(it);
if (item == NULL) if (item == NULL)
return NULL; return NULL;
Py_DECREF(item); Py_DECREF(item);
...@@ -1182,7 +1186,7 @@ islice_next(isliceobject *lz) ...@@ -1182,7 +1186,7 @@ islice_next(isliceobject *lz)
if (lz->stop != -1 && lz->cnt >= lz->stop) if (lz->stop != -1 && lz->cnt >= lz->stop)
return NULL; return NULL;
assert(PyIter_Check(it)); assert(PyIter_Check(it));
item = (*it->ob_type->tp_iternext)(it); item = iternext(it);
if (item == NULL) if (item == NULL)
return NULL; return NULL;
lz->cnt++; lz->cnt++;
...@@ -1783,10 +1787,12 @@ ifilter_next(ifilterobject *lz) ...@@ -1783,10 +1787,12 @@ ifilter_next(ifilterobject *lz)
PyObject *item; PyObject *item;
PyObject *it = lz->it; PyObject *it = lz->it;
long ok; long ok;
PyObject *(*iternext)(PyObject *);
for (;;) {
assert(PyIter_Check(it)); assert(PyIter_Check(it));
item = (*it->ob_type->tp_iternext)(it); iternext = *it->ob_type->tp_iternext;
for (;;) {
item = iternext(it);
if (item == NULL) if (item == NULL)
return NULL; return NULL;
...@@ -1932,10 +1938,12 @@ ifilterfalse_next(ifilterfalseobject *lz) ...@@ -1932,10 +1938,12 @@ ifilterfalse_next(ifilterfalseobject *lz)
PyObject *item; PyObject *item;
PyObject *it = lz->it; PyObject *it = lz->it;
long ok; long ok;
PyObject *(*iternext)(PyObject *);
for (;;) {
assert(PyIter_Check(it)); assert(PyIter_Check(it));
item = (*it->ob_type->tp_iternext)(it); iternext = *it->ob_type->tp_iternext;
for (;;) {
item = iternext(it);
if (item == NULL) if (item == NULL)
return NULL; return NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment