mirror of
https://github.com/python/cpython.git
synced 2025-09-16 05:36:29 +00:00
GH-132554: Fix tier2 FOR_ITER
implementation and optimizations (GH-135137)
This commit is contained in:
parent
d9cad074d5
commit
b90ecea9e6
12 changed files with 155 additions and 173 deletions
|
@ -3439,8 +3439,8 @@ _PyEval_LoadName(PyThreadState *tstate, _PyInterpreterFrame *frame, PyObject *na
|
|||
return value;
|
||||
}
|
||||
|
||||
_PyStackRef
|
||||
_PyForIter_NextWithIndex(PyObject *seq, _PyStackRef index)
|
||||
static _PyStackRef
|
||||
foriter_next(PyObject *seq, _PyStackRef index)
|
||||
{
|
||||
assert(PyStackRef_IsTaggedInt(index));
|
||||
assert(PyTuple_CheckExact(seq) || PyList_CheckExact(seq));
|
||||
|
@ -3459,6 +3459,30 @@ _PyForIter_NextWithIndex(PyObject *seq, _PyStackRef index)
|
|||
return PyStackRef_FromPyObjectSteal(item);
|
||||
}
|
||||
|
||||
_PyStackRef _PyForIter_VirtualIteratorNext(PyThreadState* tstate, _PyInterpreterFrame* frame, _PyStackRef iter, _PyStackRef* index_ptr)
|
||||
{
|
||||
PyObject *iter_o = PyStackRef_AsPyObjectBorrow(iter);
|
||||
_PyStackRef index = *index_ptr;
|
||||
if (PyStackRef_IsTaggedInt(index)) {
|
||||
*index_ptr = PyStackRef_IncrementTaggedIntNoOverflow(index);
|
||||
return foriter_next(iter_o, index);
|
||||
}
|
||||
PyObject *next_o = (*Py_TYPE(iter_o)->tp_iternext)(iter_o);
|
||||
if (next_o == NULL) {
|
||||
if (_PyErr_Occurred(tstate)) {
|
||||
if (_PyErr_ExceptionMatches(tstate, PyExc_StopIteration)) {
|
||||
_PyEval_MonitorRaise(tstate, frame, frame->instr_ptr);
|
||||
_PyErr_Clear(tstate);
|
||||
}
|
||||
else {
|
||||
return PyStackRef_ERROR;
|
||||
}
|
||||
}
|
||||
return PyStackRef_NULL;
|
||||
}
|
||||
return PyStackRef_FromPyObjectSteal(next_o);
|
||||
}
|
||||
|
||||
/* 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