mirror of
https://github.com/python/cpython.git
synced 2025-09-06 17:02:26 +00:00
GH-132554: "Virtual" iterators (GH-132555)
* FOR_ITER now pushes either the iterator and NULL or leaves the iterable and pushes tagged zero * NEXT_ITER uses the tagged int as the index into the sequence or, if TOS is NULL, iterates as before.
This commit is contained in:
parent
9300a596d3
commit
f6f4e8a662
25 changed files with 713 additions and 618 deletions
|
@ -3425,6 +3425,26 @@ _PyEval_LoadName(PyThreadState *tstate, _PyInterpreterFrame *frame, PyObject *na
|
|||
return value;
|
||||
}
|
||||
|
||||
_PyStackRef
|
||||
_PyForIter_NextWithIndex(PyObject *seq, _PyStackRef index)
|
||||
{
|
||||
assert(PyStackRef_IsTaggedInt(index));
|
||||
assert(PyTuple_CheckExact(seq) || PyList_CheckExact(seq));
|
||||
intptr_t i = PyStackRef_UntagInt(index);
|
||||
if (PyTuple_CheckExact(seq)) {
|
||||
size_t size = PyTuple_GET_SIZE(seq);
|
||||
if ((size_t)i >= size) {
|
||||
return PyStackRef_NULL;
|
||||
}
|
||||
return PyStackRef_FromPyObjectNew(PyTuple_GET_ITEM(seq, i));
|
||||
}
|
||||
PyObject *item = _PyList_GetItemRef((PyListObject *)seq, i);
|
||||
if (item == NULL) {
|
||||
return PyStackRef_NULL;
|
||||
}
|
||||
return PyStackRef_FromPyObjectSteal(item);
|
||||
}
|
||||
|
||||
/* Check if a 'cls' provides the given special method. */
|
||||
static inline int
|
||||
type_has_special_method(PyTypeObject *cls, PyObject *name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue