[Pyrex] Pyrex optimization
Paul Prescod
paul at prescod.net
Wed Jan 14 18:45:00 CET 2004
Jiba wrote:
>...
>
> I have arrived to similar conclusion, and i was wondering if it would be
> possible to "import" in Pyrex the list and dict classes/types, e.g. from
> python.h
I don't know precisely what you mean. It is possible to extend the Pyrex
code to deal with them but it is a lot more work than an import
statement. ;) I've started doing this.
> In addition to sequences and lists, i believe that tuples and dicts can
> be usefull too. Though such types should be used ONLY when you are 100%
> SURE that the object IS REALLY a list / dict /... (i.e. when the object
> is created in Pyrex); e.g. someone may use the bisect module on non-list
> object, but on object that behave like a list (like UserList).
If you want to be generic to any sequence type you can declare the thing
"sequence" which will include lists, tuples, UserLists, etc. If you want
the thing to only support lists (for performance) you would declare it
"list".
> So the obfuscated Pyrex version of bisect would break backward
> compatibility, IMHO.
It uses the "PySequence_" methods. On the other hand, the obfuscated
_heapq_ uses the "PyList_" methods but that was because the C heapq
module which is slated to be added to Python does that too. The Pyrex
version is as fragile and backwards incompatible as the C version and
almost as fast. If I were not competing with a module that already
"cheated" I wouldn't cheat.
Paul Prescod
More information about the Pyrex
mailing list