[Cython] Cython syntax to pre-allocate lists for performance

Robert Bradshaw robertwb at gmail.com
Fri Mar 8 00:41:54 CET 2013


On Thu, Mar 7, 2013 at 3:19 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Nikita Nemkin wrote:
>>
>> Sorry, accidental early send. Previous mail continued...
>>
>> [None] * N makes an extra pass over the list to assign None to each item
>> (and also incref None n times).
>
>
> Maybe this could be optimised by adding N to the reference
> count instead of incrementing it N times?

I'd be surprised if the C compiler doesn't.

http://hg.python.org/cpython/file/1d4849f9e37d/Objects/listobject.c#l515


More information about the cython-devel mailing list