Chris Angelico, 12.08.2012 01:22:
>> Other idea to improve this optimizer:
>>  - move invariant out of loops. Example: "x=[]; for i in range(10):
>> x.append(i)" => "x=[]; x_append=x.append; for i in range(10):
>> x_append(i)". Require to infer the type of variables.
> 
> But this is risky. It's theoretically possible for x.append to replace
> itself. Sure it may not be a normal or common thing to do, but it's
> possible.

Not only that. It changes semantics. If x.append is not defined, the
exception would now be raised outside of the loop, and the loop itself may
have side-effects already. In fact, the mere lookup of x.append may have
side effects as well ...

Stefan


_______________________________________________
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