Skip to content
Prev Previous commit
Next Next commit
Address code review
  • Loading branch information
corona10 committed Feb 14, 2024
commit bec617a5012e77b8891bdf9b0b05b375dc9fcb9a
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
For an empty reverse iterator for list will be reduced to :func:`reversed`.
Patch by Donghee Na
6 changes: 4 additions & 2 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2614,7 +2614,7 @@ dummy_func(
assert(Py_TYPE(iter) == &PyListIter_Type);
STAT_INC(FOR_ITER, hit);
PyListObject *seq = it->it_seq;
if (seq == NULL || it->it_index >= PyList_GET_SIZE(seq)) {
if ((size_t)it->it_index >= (size_t)PyList_GET_SIZE(seq)) {
#ifndef Py_GIL_DISABLED
if (seq != NULL) {
it->it_seq = NULL;
Expand All @@ -2635,8 +2635,10 @@ dummy_func(
_PyListIterObject *it = (_PyListIterObject *)iter;
assert(Py_TYPE(iter) == &PyListIter_Type);
PyListObject *seq = it->it_seq;
#ifndef Py_GIL_DISABLED
DEOPT_IF(seq == NULL);
DEOPT_IF(it->it_index >= PyList_GET_SIZE(seq));
#endif
Comment thread
corona10 marked this conversation as resolved.
Outdated
DEOPT_IF((size_t)it->it_index >= (size_t)PyList_GET_SIZE(seq));
}

op(_ITER_NEXT_LIST, (iter -- iter, next)) {
Expand Down
4 changes: 3 additions & 1 deletion Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.