summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-10-06 17:45:17 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-10-06 17:45:17 (GMT)
commit7254e5a3edd85563d333ba5aa2978d7cd7daa96a (patch)
treee1baf68ff877e117ef2ee5233ac838ba4837db10 /Objects/object.c
parent8c18f2585032a01b04a99b1acd31a71c7e46f8cb (diff)
downloadcpython-7254e5a3edd85563d333ba5aa2978d7cd7daa96a.zip
cpython-7254e5a3edd85563d333ba5aa2978d7cd7daa96a.tar.gz
cpython-7254e5a3edd85563d333ba5aa2978d7cd7daa96a.tar.bz2
_PyObject_GetDictPtr():
+ Use the _PyObject_VAR_SIZE macro to compute object size. + Break the computation into lines convenient for debugger inspection. + Speed the round-up-to-pointer-size computation.
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/Objects/object.c b/Objects/object.c
index a008245..ed5f360 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1157,15 +1157,19 @@ _PyObject_GetDictPtr(PyObject *obj)
if (dictoffset == 0)
return NULL;
if (dictoffset < 0) {
- dictoffset += tp->tp_basicsize;
- dictoffset += tp->tp_itemsize * ((PyVarObject *)obj)->ob_size;
+ /* dictoffset is positive by the time we're ready to round
+ it, and compilers can generate faster rounding code if
+ they know that. */
+ unsigned long udo; /* unsigned dictoffset */
+ const long nitems = ((PyVarObject *)obj)->ob_size;
+ const long size = _PyObject_VAR_SIZE(tp, nitems);
+
+ dictoffset += size;
assert(dictoffset > 0); /* Sanity check */
- /* Round up, if necessary */
- if (dictoffset % PTRSIZE != 0) {
- dictoffset /= PTRSIZE;
- dictoffset += 1;
- dictoffset *= PTRSIZE;
- }
+ /* Round up to multiple of PTRSIZE. */
+ udo = (unsigned long)dictoffset;
+ udo = ((udo + PTRSIZE-1) / PTRSIZE) * PTRSIZE;
+ dictoffset = (long)udo;
}
return (PyObject **) ((char *)obj + dictoffset);
}