diff options
author | Raymond Hettinger <python@rcn.com> | 2002-05-31 21:40:38 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2002-05-31 21:40:38 (GMT) |
commit | 14bd6de0ec6468487598f4ad4c14aa0a2742e641 (patch) | |
tree | 92a338f0fc9b497e05bc28063c5a1c7f09bbd48c /Objects/iterobject.c | |
parent | 59b2a74c752578cb67b02b6966f283fd049f646a (diff) | |
download | cpython-14bd6de0ec6468487598f4ad4c14aa0a2742e641.zip cpython-14bd6de0ec6468487598f4ad4c14aa0a2742e641.tar.gz cpython-14bd6de0ec6468487598f4ad4c14aa0a2742e641.tar.bz2 |
SF 560736. Optimize list iteration by filling the tp_iter slot.
Diffstat (limited to 'Objects/iterobject.c')
-rw-r--r-- | Objects/iterobject.c | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/Objects/iterobject.c b/Objects/iterobject.c index de9f2f9..ce1fe3d 100644 --- a/Objects/iterobject.c +++ b/Objects/iterobject.c @@ -68,25 +68,15 @@ iter_iternext(PyObject *iterator) it = (seqiterobject *)iterator; seq = it->it_seq; - if (PyList_CheckExact(seq)) { - PyObject *item; - if (it->it_index >= PyList_GET_SIZE(seq)) { - return NULL; - } - item = PyList_GET_ITEM(seq, it->it_index); - it->it_index++; - Py_INCREF(item); - return item; - } if (PyTuple_CheckExact(seq)) { - PyObject *item; - if (it->it_index >= PyTuple_GET_SIZE(seq)) { - return NULL; + if (it->it_index < PyTuple_GET_SIZE(seq)) { + PyObject *item; + item = PyTuple_GET_ITEM(seq, it->it_index); + it->it_index++; + Py_INCREF(item); + return item; } - item = PyTuple_GET_ITEM(seq, it->it_index); - it->it_index++; - Py_INCREF(item); - return item; + return NULL; } else { PyObject *result = PySequence_ITEM(seq, it->it_index); |