[New-bugs-announce] [issue11471] If without else generates redundant jump
report at bugs.python.org
Fri Mar 11 22:49:16 CET 2011
New submission from Eugene Toder <eltoder at gmail.com>:
If statement without else part generates unnecessary JUMP_FORWARD insn with jumps right to the next insn:
>>> def foo(x):
if x: x = 1
2 0 LOAD_FAST 0 (x)
3 POP_JUMP_IF_FALSE 15
6 LOAD_CONST 1 (1)
9 STORE_FAST 0 (x)
12 JUMP_FORWARD 0 (to 15)
>> 15 LOAD_CONST 0 (None)
This patch suppresses generation of this jump.
Testing revealed another issue: when AST is produced from string empty 'orelse' sequences are represented with NULLs. However when AST is converted from Python AST objects empty 'orelse' is a pointer to 0-length sequence. I've changed this to produce NULL pointers, like in the string case. This uses less memory and doesn't introduce different code path in compiler. Without this change test_compile failed with my first change.
make test passes.
components: Interpreter Core
title: If without else generates redundant jump
versions: Python 3.3
Added file: http://bugs.python.org/file21091/if_no_else.patch
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce