|
Quick 'len()' speedup for Pyrex: msg#00046python.pyrex
If your Pyrex code uses the 'len()' builtin, here's a handy quick fix you can pop in at the beginning of your code: cdef extern from "Python.h": int len "PySequence_Length" (object o) except -1 This basically tells Pyrex to treat len() as a C call to its C API equivalent, rather than doing a global name + builtins lookup, followed by a tuple construction, PyObject_CallObject, and tuple deallocation. I expect there may be other builtins that are similarly replaceable, making your Pyrex code look like idiomatic Python, but compile to "real C" instead of Python emulation in C. For example, 2-argument getattr can probably be rendered as: cdef extern from "Python.h": object getattr "PyObject_GetAttr" (object o, object a) |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Bug? SystemError: error return without exception set: 00046, Atsuo Ishimoto |
|---|---|
| Next by Date: | Re: distutils.cfg and weave etc....: 00046, Voidspace |
| Previous by Thread: | Pyrex IDEi: 00046, Voidspace |
| Next by Thread: | Re: Quick 'len()' speedup for Pyrex: 00046, Jiba |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |