diff options
author | Raymond Hettinger <python@rcn.com> | 2004-03-17 04:27:44 +0000 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-03-17 04:27:44 +0000 |
commit | 0faa1ca51d98b41fda4eb4fb25704981ea3bf2bb (patch) | |
tree | 4351977b4ac230183fb90f3d6ecf01955c69f659 /Modules/itertoolsmodule.c | |
parent | bdda9f389a21244b43f8a248cb9eda02f9d80ae4 (diff) | |
download | cpython-git-0faa1ca51d98b41fda4eb4fb25704981ea3bf2bb.tar.gz |
Speedup the inner loops for dropwhile(), islice(), ifilter(), and
ifilterfalse().
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r-- | Modules/itertoolsmodule.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 517975b367..3ad26d5b2c 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -835,10 +835,12 @@ dropwhile_next(dropwhileobject *lz) PyObject *item, *good; PyObject *it = lz->it; long ok; + PyObject *(*iternext)(PyObject *); + assert(PyIter_Check(it)); + iternext = *it->ob_type->tp_iternext; for (;;) { - assert(PyIter_Check(it)); - item = (*it->ob_type->tp_iternext)(it); + item = iternext(it); if (item == NULL) return NULL; if (lz->start == 1) @@ -1170,10 +1172,12 @@ islice_next(isliceobject *lz) PyObject *item; PyObject *it = lz->it; long oldnext; + PyObject *(*iternext)(PyObject *); + assert(PyIter_Check(it)); + iternext = *it->ob_type->tp_iternext; while (lz->cnt < lz->next) { - assert(PyIter_Check(it)); - item = (*it->ob_type->tp_iternext)(it); + item = iternext(it); if (item == NULL) return NULL; Py_DECREF(item); @@ -1182,7 +1186,7 @@ islice_next(isliceobject *lz) if (lz->stop != -1 && lz->cnt >= lz->stop) return NULL; assert(PyIter_Check(it)); - item = (*it->ob_type->tp_iternext)(it); + item = iternext(it); if (item == NULL) return NULL; lz->cnt++; @@ -1783,10 +1787,12 @@ ifilter_next(ifilterobject *lz) PyObject *item; PyObject *it = lz->it; long ok; + PyObject *(*iternext)(PyObject *); + assert(PyIter_Check(it)); + iternext = *it->ob_type->tp_iternext; for (;;) { - assert(PyIter_Check(it)); - item = (*it->ob_type->tp_iternext)(it); + item = iternext(it); if (item == NULL) return NULL; @@ -1932,10 +1938,12 @@ ifilterfalse_next(ifilterfalseobject *lz) PyObject *item; PyObject *it = lz->it; long ok; + PyObject *(*iternext)(PyObject *); + assert(PyIter_Check(it)); + iternext = *it->ob_type->tp_iternext; for (;;) { - assert(PyIter_Check(it)); - item = (*it->ob_type->tp_iternext)(it); + item = iternext(it); if (item == NULL) return NULL; |