Brett Cannon wrote:

>>I don't know to what extent these kind of optimizations are available to
>>cpython.  For example, are constant calculations removed from loops?
> 
> If you mean ``2+3``, then yes.

Actually, no. Constant folding *could* be done, but it currently isn't:

 >>> def f():
...   return 2+3
...
 >>> import dis
 >>> dis.dis(f)
   2           0 LOAD_CONST               1 (2)
               3 LOAD_CONST               2 (3)
               6 BINARY_ADD
               7 RETURN_VALUE
               8 LOAD_CONST               0 (None)
              11 RETURN_VALUE
 >>>

-- 
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,          | A citizen of NewZealandCorp, a       |
Christchurch, New Zealand          | wholly-owned subsidiary of USA Inc.  |
[EMAIL PROTECTED]          +--------------------------------------+
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to