[Pyrex] Pyrex optimization chitchat
Phillip J. Eby
pje at telecommunity.com
Thu Jan 22 02:53:14 CET 2004
At 02:27 PM 1/22/04 +1300, Greg Ewing wrote:
>Paul Prescod:
>
> > cdef x(list foo):
> > foo.append(5)
> >
> > Should the compiler expand that to optimized PyList_Append code or call
> > a method by name?
>
>I think it really has to do a method lookup. Even if foo is
>declared to be a list, it might be a subclass of list that
>overrides the append method.
But what would be the point in declaring it a list, then? :)
OTOH, how about:
cdef x(exact list foo):
foo.append(5)
where 'exact' means that the type match uses PyList_CheckExact (or however
it's spelled). This would meet the use case of e.g.:
cdef exact list items
for x in something:
items.append(x)
IOW, most of the places I use the direct Python APIs for performance are
where I *know* I've got a list (or dictionary, or tuple), because I'm the
one creating it, as either a local variable or a private attribute of an
object.
More information about the Pyrex
mailing list