Fast construction of Python list from large C array of int's - Extension Module

hg hansgeunsmeyer at earthlink.net
Tue Nov 19 10:39:45 EST 2002


quadric at primenet.com wrote in message news:<mailman.1037647226.1409.python-list at python.org>...

> Is this the fastest way to do this?

It will probably be a bit faster if you use PyList_SETITEM instead of
PyList_SetItem.  Since you're creating a brand new list, it's safe to
use the macro. (The macro just plugs in the new values, without
checking that the list is really a PyList, without checking for buffer
over/underflow, and without trying to decrease the ref count of an old
list item.)

> Any inherent dangers here?

As Alex already pointed out, you definitely have to check that neither
your list nor any of the PyLongs is NULL.

Hans



More information about the Python-list mailing list