diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2022-11-30 21:04:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-30 21:04:30 (GMT) |
commit | 787764219f874ce2035699ed772af1e9f3bbf813 (patch) | |
tree | cad58073df5fba2f204c4633054ba6a91daf542e /Python | |
parent | 9628136fac997847b4662e6a17faf06d2a0507eb (diff) | |
download | cpython-787764219f874ce2035699ed772af1e9f3bbf813.zip cpython-787764219f874ce2035699ed772af1e9f3bbf813.tar.gz cpython-787764219f874ce2035699ed772af1e9f3bbf813.tar.bz2 |
gh-89189: More compact range iterator (GH-27986)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bytecodes.c | 7 | ||||
-rw-r--r-- | Python/generated_cases.c.h | 7 |
2 files changed, 8 insertions, 6 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c index a1f910d..41dd1ac 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -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; } diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index ae8fdd5..3af60b8 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -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; } |