Antoine Pitrou <pit...@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue11244>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to