From 71adc9328d593449a7d8d3bff45b09bf87afa59e Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Mon, 28 Sep 2009 16:52:40 +0000 Subject: [PATCH] Style/consistency/nano-optimization nit: replace occurrences of (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 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Objects/longobject.c b/Objects/longobject.c index d284b4f376c..376973eb0db 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -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; }