mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
gh-89189: More compact range iterator (GH-27986)
This commit is contained in:
parent
9628136fac
commit
787764219f
7 changed files with 88 additions and 50 deletions
|
@ -2620,14 +2620,15 @@ dummy_func(
|
|||
STAT_INC(FOR_ITER, hit);
|
||||
_Py_CODEUNIT next = next_instr[INLINE_CACHE_ENTRIES_FOR_ITER];
|
||||
assert(_PyOpcode_Deopt[_Py_OPCODE(next)] == STORE_FAST);
|
||||
if (r->index >= r->len) {
|
||||
if (r->len <= 0) {
|
||||
STACK_SHRINK(1);
|
||||
Py_DECREF(r);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1);
|
||||
}
|
||||
else {
|
||||
long value = (long)(r->start +
|
||||
(unsigned long)(r->index++) * r->step);
|
||||
long value = r->start;
|
||||
r->start = value + r->step;
|
||||
r->len--;
|
||||
if (_PyLong_AssignValue(&GETLOCAL(_Py_OPARG(next)), value) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
|
7
Python/generated_cases.c.h
generated
7
Python/generated_cases.c.h
generated
|
@ -2638,14 +2638,15 @@
|
|||
STAT_INC(FOR_ITER, hit);
|
||||
_Py_CODEUNIT next = next_instr[INLINE_CACHE_ENTRIES_FOR_ITER];
|
||||
assert(_PyOpcode_Deopt[_Py_OPCODE(next)] == STORE_FAST);
|
||||
if (r->index >= r->len) {
|
||||
if (r->len <= 0) {
|
||||
STACK_SHRINK(1);
|
||||
Py_DECREF(r);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1);
|
||||
}
|
||||
else {
|
||||
long value = (long)(r->start +
|
||||
(unsigned long)(r->index++) * r->step);
|
||||
long value = r->start;
|
||||
r->start = value + r->step;
|
||||
r->len--;
|
||||
if (_PyLong_AssignValue(&GETLOCAL(_Py_OPARG(next)), value) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue