[issue11471] If without else generates redundant jump

Eugene Toder 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

>>> dis(foo)
  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) 
             18 RETURN_VALUE         

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
files: if_no_else.patch
keywords: patch
messages: 130623
nosy: eltoder
priority: normal
severity: normal
status: open
title: If without else generates redundant jump
type: performance
versions: Python 3.3
Added file: http://bugs.python.org/file21091/if_no_else.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11471>
_______________________________________


More information about the Python-bugs-list mailing list