The OID-packing functions in ZODB/utils.py are a
noticeably performance bottleneck. This patch rewrites
them in C to speed things up.
Details:
* adds ZODB/oidutils.h to define C macros for OID
packing/unpacking
* adds ZODB/oidutils.c (aka the ZODB.oidutils
extension module) to
expose Python wrappers for those C macros
* eliminate most of the code in ZODB/utils.h, and
replace it with
imports from ZODB.oidutils
Logged In: YES
user_id=31435
Python.h automatically includes assert.h -- no need to
include assert.h yourself. There are no assert() calls in the C
code anyway, so it's unclear why assert.h is there regardless.
Please remove the typedefs for uint64. Python spells this
unsigned LONG_LONG
and you can too <wink> -- including Python.h makes
LONG_LONG available, and it expands to the right platform-
specific stuff on all Python platforms (in particular, the code
you've got now won't compile on Windows).
In the PyInt_Check case, casting the result of
PyInt_AS_LONG to (unsigned int) will do a wrong thing on 64-
bit platforms (it will throw away the most-significant 32 bits of
the 64-bit result PyInt_AS_LONG returns on such boxes).
You need to check for an error return from
PyLong_AsUnsignedLongLong (for example, it can fail if the
Python long doesn't fit in 64 bits). Safest is to do
if (oid_i == (unsigned LONG_LONG)-1 && PyErr_Occurred())
return NULL;
after the if/else nest.
p64() will be more efficient if declared METH_O.