Commit 24f5785f authored by Mark Dickinson's avatar Mark Dickinson

Merged revisions 75110 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r75110 | mark.dickinson | 2009-09-28 17:52:40 +0100 (Mon, 28 Sep 2009) | 9 lines

  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).
........
parent 3c976a04
...@@ -389,7 +389,7 @@ PyLong_AsLongAndOverflow(PyObject *vv, int *overflow) ...@@ -389,7 +389,7 @@ PyLong_AsLongAndOverflow(PyObject *vv, int *overflow)
} }
while (--i >= 0) { while (--i >= 0) {
prev = x; prev = x;
x = (x << PyLong_SHIFT) + v->ob_digit[i]; x = (x << PyLong_SHIFT) | v->ob_digit[i];
if ((x >> PyLong_SHIFT) != prev) { if ((x >> PyLong_SHIFT) != prev) {
*overflow = Py_SIZE(v) > 0 ? 1 : -1; *overflow = Py_SIZE(v) > 0 ? 1 : -1;
goto exit; goto exit;
...@@ -459,7 +459,7 @@ PyLong_AsSsize_t(PyObject *vv) { ...@@ -459,7 +459,7 @@ PyLong_AsSsize_t(PyObject *vv) {
} }
while (--i >= 0) { while (--i >= 0) {
prev = x; prev = x;
x = (x << PyLong_SHIFT) + v->ob_digit[i]; x = (x << PyLong_SHIFT) | v->ob_digit[i];
if ((x >> PyLong_SHIFT) != prev) if ((x >> PyLong_SHIFT) != prev)
goto overflow; goto overflow;
} }
...@@ -508,7 +508,7 @@ PyLong_AsUnsignedLong(PyObject *vv) ...@@ -508,7 +508,7 @@ PyLong_AsUnsignedLong(PyObject *vv)
} }
while (--i >= 0) { while (--i >= 0) {
prev = x; prev = x;
x = (x << PyLong_SHIFT) + v->ob_digit[i]; x = (x << PyLong_SHIFT) | v->ob_digit[i];
if ((x >> PyLong_SHIFT) != prev) { if ((x >> PyLong_SHIFT) != prev) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"python int too large to convert to C unsigned long"); "python int too large to convert to C unsigned long");
...@@ -546,7 +546,7 @@ PyLong_AsSize_t(PyObject *vv) ...@@ -546,7 +546,7 @@ PyLong_AsSize_t(PyObject *vv)
} }
while (--i >= 0) { while (--i >= 0) {
prev = x; prev = x;
x = (x << PyLong_SHIFT) + v->ob_digit[i]; x = (x << PyLong_SHIFT) | v->ob_digit[i];
if ((x >> PyLong_SHIFT) != prev) { if ((x >> PyLong_SHIFT) != prev) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"Python int too large to convert to C size_t"); "Python int too large to convert to C size_t");
...@@ -584,7 +584,7 @@ _PyLong_AsUnsignedLongMask(PyObject *vv) ...@@ -584,7 +584,7 @@ _PyLong_AsUnsignedLongMask(PyObject *vv)
i = -i; i = -i;
} }
while (--i >= 0) { while (--i >= 0) {
x = (x << PyLong_SHIFT) + v->ob_digit[i]; x = (x << PyLong_SHIFT) | v->ob_digit[i];
} }
return x * sign; return x * sign;
} }
...@@ -1451,7 +1451,7 @@ _PyLong_AsUnsignedLongLongMask(PyObject *vv) ...@@ -1451,7 +1451,7 @@ _PyLong_AsUnsignedLongLongMask(PyObject *vv)
i = -i; i = -i;
} }
while (--i >= 0) { while (--i >= 0) {
x = (x << PyLong_SHIFT) + v->ob_digit[i]; x = (x << PyLong_SHIFT) | v->ob_digit[i];
} }
return x * sign; return x * sign;
} }
...@@ -1625,7 +1625,7 @@ inplace_divrem1(digit *pout, digit *pin, Py_ssize_t size, digit n) ...@@ -1625,7 +1625,7 @@ inplace_divrem1(digit *pout, digit *pin, Py_ssize_t size, digit n)
pout += size; pout += size;
while (--size >= 0) { while (--size >= 0) {
digit hi; digit hi;
rem = (rem << PyLong_SHIFT) + *--pin; rem = (rem << PyLong_SHIFT) | *--pin;
*--pout = hi = (digit)(rem / n); *--pout = hi = (digit)(rem / n);
rem -= (twodigits)hi * n; rem -= (twodigits)hi * n;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment