mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
SF 560736. Optimize list iteration by filling the tp_iter slot.
This commit is contained in:
parent
59b2a74c75
commit
14bd6de0ec
3 changed files with 126 additions and 18 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue