diff options
author | Raymond Hettinger <python@rcn.com> | 2002-08-09 01:30:17 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2002-08-09 01:30:17 (GMT) |
commit | 48923c5533865173894bb4b1d8f9851430f49f8b (patch) | |
tree | 54706b30488cb7eb8022e5f9579e305b611850f2 /Objects/iterobject.c | |
parent | 8da9da0ccc7c63aff0fbc5d65b3e0ca28a754090 (diff) | |
download | cpython-48923c5533865173894bb4b1d8f9851430f49f8b.zip cpython-48923c5533865173894bb4b1d8f9851430f49f8b.tar.gz cpython-48923c5533865173894bb4b1d8f9851430f49f8b.tar.bz2 |
Moved special case for tuples from iterobject.c to
tupleobject.c. Makes the code in iterobject.c cleaner
and speeds-up the general case by not checking for
tuples everytime. SF Patch #592065.
Diffstat (limited to 'Objects/iterobject.c')
-rw-r--r-- | Objects/iterobject.c | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/Objects/iterobject.c b/Objects/iterobject.c index 447edba..4dc225a 100644 --- a/Objects/iterobject.c +++ b/Objects/iterobject.c @@ -55,6 +55,7 @@ iter_iternext(PyObject *iterator) { seqiterobject *it; PyObject *seq; + PyObject *result; assert(PySeqIter_Check(iterator)); it = (seqiterobject *)iterator; @@ -62,33 +63,19 @@ iter_iternext(PyObject *iterator) if (seq == NULL) return NULL; - if (PyTuple_CheckExact(seq)) { - 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; - } + result = PySequence_GetItem(seq, it->it_index); + if (result != NULL) { + it->it_index++; + return result; + } + if (PyErr_ExceptionMatches(PyExc_IndexError) || + PyErr_ExceptionMatches(PyExc_StopIteration)) + { + PyErr_Clear(); Py_DECREF(seq); it->it_seq = NULL; - return NULL; - } - else { - PyObject *result = PySequence_GetItem(seq, it->it_index); - if (result != NULL) { - it->it_index++; - return result; - } - if (PyErr_ExceptionMatches(PyExc_IndexError) || - PyErr_ExceptionMatches(PyExc_StopIteration)) - { - PyErr_Clear(); - Py_DECREF(seq); - it->it_seq = NULL; - } - return NULL; } + return NULL; } PyTypeObject PySeqIter_Type = { |