On Oct 25, 2009, at 11:53 AM, Lisandro Dalcin wrote: > On Sun, Oct 25, 2009 at 2:39 PM, Sturla Molden <[email protected]> > wrote: >> I just realized the Python does not provide a fast way of popping an >> item from a list, just append. I.e. there is a PyList_Append, but no >> PyList_Pop. And in Python's code for _listobject.c, the function >> listpop >> is declared static. When using a list as a stack (a common case for >> Python lists), a fast pop is just as important as a fast append. >> > > Indeed. +1 for the idea, but... > >> Since the function listpop is static, the fastest way to pop a list >> is >> to grab the method named "pop" from the PyTypeObject. This might >> not be >> obvious to everyone, so I think it is an optimization that Cython >> should do. >> > > -0.5 for the implementation... The hack is cute, but still have to > make a listpop(self,args), were you need to create a tuple to make the > call... I think Cython could generate a custom, inline function > implementing l.pop([n]) and fast dispatch to it if the object is > exactly a list ...
http://hg.cython.org/cython-devel/rev/2e3dda4a7d23 - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
