[Python-Dev] Release of astoptimizer 0.3

Serhiy Storchaka storchaka at gmail.com
Wed Sep 12 09:55:38 CEST 2012


On 12.09.12 00:47, Victor Stinner wrote:
>> x = x + [y] => x.append(y)
>> x = x + [y, z] => x.extend([y, z])
>
> It behaves differently if x is not a list, but str for example.

Actually even worse. Transformations applicable only if x has not 
aliases. Pseudocode:

   if type(x) is list and refcount(x) == 1:
       list.append(x, y)
   else:
       x = x + [y]

This optimization can be done only in the interpreter, otherwise 
overhead costs will be too high.



More information about the Python-Dev mailing list