[issue11244] Negative tuple elements produce inefficient code.

Antoine Pitrou report at bugs.python.org
Sat Feb 19 00:09:25 CET 2011


Antoine Pitrou <pitrou at free.fr> added the comment:

Here is a patch that enables advanced (recursive) constant folding.
Example:

python -c "import dis; f=lambda x: x in {(3*-5)+(-1-6),(1,-2,3)*2,None};dis.dis(f)"

With 3.1:
  1           0 LOAD_FAST                0 (x) 
              3 LOAD_CONST               7 (-15) 
              6 LOAD_CONST               8 (-7) 
              9 BINARY_ADD           
             10 LOAD_CONST              10 ((1, -2, 3, 1, -2, 3)) 
             13 LOAD_CONST              11 (None) 
             16 BUILD_SET                3 
             19 COMPARE_OP               6 (in) 
             22 RETURN_VALUE         

With 3.2+patch:
  1           0 LOAD_FAST                0 (x) 
              3 LOAD_CONST              14 (frozenset({None, -22, (1, -2, 3, 1, -2, 3)})) 
              6 COMPARE_OP               6 (in) 
              9 RETURN_VALUE

----------
Added file: http://bugs.python.org/file20790/constfold.patch

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


More information about the Python-bugs-list mailing list