]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
_PyObject_GetDictPtr():
authorTim Peters <tim.peters@gmail.com>
Sat, 6 Oct 2001 17:45:17 +0000 (17:45 +0000)
committerTim Peters <tim.peters@gmail.com>
Sat, 6 Oct 2001 17:45:17 +0000 (17:45 +0000)
+ 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.

Objects/object.c

index a0082456ce9bafba8341c3ba90f33e823ea75e09..ed5f3601bc15e50c683d11630473f8449a642a9c 100644 (file)
@@ -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);
 }