Skip to content

Commit 225e36a

Browse files
committed
Move GET_ITER back to genexpr creation
1 parent c011b5b commit 225e36a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Python/codegen.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4411,7 +4411,7 @@ codegen_sync_comprehension_generator(compiler *c, location loc,
44114411

44124412
comprehension_ty gen = (comprehension_ty)asdl_seq_GET(generators,
44134413
gen_index);
4414-
4414+
int is_outer_genexpr = gen_index == 0 && type == COMP_GENEXP;
44154415
if (!iter_on_stack) {
44164416
if (gen_index == 0) {
44174417
assert(METADATA(c)->u_argcount == 1);
@@ -4442,14 +4442,15 @@ codegen_sync_comprehension_generator(compiler *c, location loc,
44424442
}
44434443
if (IS_JUMP_TARGET_LABEL(start)) {
44444444
VISIT(c, expr, gen->iter);
4445-
ADDOP(c, LOC(gen->iter), GET_ITER);
44464445
}
44474446
}
44484447
}
44494448

44504449
if (IS_JUMP_TARGET_LABEL(start)) {
44514450
depth++;
4452-
ADDOP(c, LOC(gen->iter), GET_ITER);
4451+
if (!is_outer_genexpr) {
4452+
ADDOP(c, LOC(gen->iter), GET_ITER);
4453+
}
44534454
USE_LABEL(c, start);
44544455
ADDOP_JUMP(c, LOC(gen->iter), FOR_ITER, anchor);
44554456
}
@@ -4775,6 +4776,7 @@ codegen_comprehension(compiler *c, expr_ty e, int type,
47754776
location loc = LOC(e);
47764777

47774778
outermost = (comprehension_ty) asdl_seq_GET(generators, 0);
4779+
int is_sync_genexpr = type == COMP_GENEXP && !outermost->is_async;
47784780
if (is_inlined) {
47794781
VISIT(c, expr, outermost->iter);
47804782
if (push_inlined_comprehension_state(c, loc, entry, &inline_state)) {
@@ -4851,6 +4853,9 @@ codegen_comprehension(compiler *c, expr_ty e, int type,
48514853
Py_CLEAR(co);
48524854

48534855
VISIT(c, expr, outermost->iter);
4856+
if (is_sync_genexpr) {
4857+
ADDOP(c, loc, GET_ITER);
4858+
}
48544859
ADDOP_I(c, loc, CALL, 0);
48554860

48564861
if (is_async_comprehension && type != COMP_GENEXP) {

0 commit comments

Comments
 (0)