Kaydet (Commit) e7811fca authored tarafından Antoine Pitrou's avatar Antoine Pitrou

Closes #11471: avoid generating a JUMP_FORWARD instruction at the end of an…

Closes #11471: avoid generating a JUMP_FORWARD instruction at the end of an if-block if there is no else-clause.

Original patch by Eugene Toder.
üst 87538e7b
This diff is collapsed.
...@@ -10,6 +10,9 @@ Release date: TBA ...@@ -10,6 +10,9 @@ Release date: TBA
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #11471: avoid generating a JUMP_FORWARD instruction at the end of
an if-block if there is no else-clause. Original patch by Eugene Toder.
- Issue #22215: Now ValueError is raised instead of TypeError when str or bytes - Issue #22215: Now ValueError is raised instead of TypeError when str or bytes
argument contains not permitted null character or byte. argument contains not permitted null character or byte.
......
...@@ -1940,7 +1940,7 @@ compiler_if(struct compiler *c, stmt_ty s) ...@@ -1940,7 +1940,7 @@ compiler_if(struct compiler *c, stmt_ty s)
} else if (constant == 1) { } else if (constant == 1) {
VISIT_SEQ(c, stmt, s->v.If.body); VISIT_SEQ(c, stmt, s->v.If.body);
} else { } else {
if (s->v.If.orelse) { if (asdl_seq_LEN(s->v.If.orelse)) {
next = compiler_new_block(c); next = compiler_new_block(c);
if (next == NULL) if (next == NULL)
return 0; return 0;
...@@ -1950,8 +1950,8 @@ compiler_if(struct compiler *c, stmt_ty s) ...@@ -1950,8 +1950,8 @@ compiler_if(struct compiler *c, stmt_ty s)
VISIT(c, expr, s->v.If.test); VISIT(c, expr, s->v.If.test);
ADDOP_JABS(c, POP_JUMP_IF_FALSE, next); ADDOP_JABS(c, POP_JUMP_IF_FALSE, next);
VISIT_SEQ(c, stmt, s->v.If.body); VISIT_SEQ(c, stmt, s->v.If.body);
if (asdl_seq_LEN(s->v.If.orelse)) {
ADDOP_JREL(c, JUMP_FORWARD, end); ADDOP_JREL(c, JUMP_FORWARD, end);
if (s->v.If.orelse) {
compiler_use_next_block(c, next); compiler_use_next_block(c, next);
VISIT_SEQ(c, stmt, s->v.If.orelse); VISIT_SEQ(c, stmt, s->v.If.orelse);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment