]> granicus.if.org Git - python/commitdiff
Style/consistency/nano-optimization nit: replace occurrences of
authorMark Dickinson <dickinsm@gmail.com>
Mon, 28 Sep 2009 16:52:40 +0000 (16:52 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Mon, 28 Sep 2009 16:52:40 +0000 (16:52 +0000)
  (high_bits << PyLong_SHIFT) + low_bits with
  (high_bits << PyLong_SHIFT) | low_bits
in Objects/longobject.c.  Motivation:
 - shouldn't unnecessarily mix bit ops with arithmetic ops (style)
 - this pattern should be spelt the same way thoughout (consistency)
 - it's very very very slightly faster: no need to worry about
   carries to the high digit (nano-optimization).

Objects/longobject.c

index d284b4f376c3846b069fef4eebdcf3352aa5bb46..376973eb0dbac4c3c83e5d4f96f94e68bc5dd7b1 100644 (file)
@@ -251,7 +251,7 @@ PyLong_AsLong(PyObject *vv)
        }
        while (--i >= 0) {
                prev = x;
-               x = (x << PyLong_SHIFT) + v->ob_digit[i];
+               x = (x << PyLong_SHIFT) | v->ob_digit[i];
                if ((x >> PyLong_SHIFT) != prev)
                        goto overflow;
        }
@@ -296,7 +296,7 @@ PyLong_AsSsize_t(PyObject *vv) {
        }
        while (--i >= 0) {
                prev = x;
-               x = (x << PyLong_SHIFT) + v->ob_digit[i];
+               x = (x << PyLong_SHIFT) | v->ob_digit[i];
                if ((x >> PyLong_SHIFT) != prev)
                        goto overflow;
        }
@@ -350,7 +350,7 @@ PyLong_AsUnsignedLong(PyObject *vv)
        }
        while (--i >= 0) {
                prev = x;
-               x = (x << PyLong_SHIFT) + v->ob_digit[i];
+               x = (x << PyLong_SHIFT) | v->ob_digit[i];
                if ((x >> PyLong_SHIFT) != prev) {
                        PyErr_SetString(PyExc_OverflowError,
                                "long int too large to convert");
@@ -386,7 +386,7 @@ PyLong_AsUnsignedLongMask(PyObject *vv)
                i = -i;
        }
        while (--i >= 0) {
-               x = (x << PyLong_SHIFT) + v->ob_digit[i];
+               x = (x << PyLong_SHIFT) | v->ob_digit[i];
        }
        return x * sign;
 }
@@ -1170,7 +1170,7 @@ PyLong_AsUnsignedLongLongMask(PyObject *vv)
                i = -i;
        }
        while (--i >= 0) {
-               x = (x << PyLong_SHIFT) + v->ob_digit[i];
+               x = (x << PyLong_SHIFT) | v->ob_digit[i];
        }
        return x * sign;
 }
@@ -1336,7 +1336,7 @@ inplace_divrem1(digit *pout, digit *pin, Py_ssize_t size, digit n)
        pout += size;
        while (--size >= 0) {
                digit hi;
-               rem = (rem << PyLong_SHIFT) + *--pin;
+               rem = (rem << PyLong_SHIFT) | *--pin;
                *--pout = hi = (digit)(rem / n);
                rem -= (twodigits)hi * n;
        }