]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
int_lshift(): Simplified/sped overflow-checking.
authorTim Peters <tim.peters@gmail.com>
Sun, 11 Aug 2002 17:54:42 +0000 (17:54 +0000)
committerTim Peters <tim.peters@gmail.com>
Sun, 11 Aug 2002 17:54:42 +0000 (17:54 +0000)
Objects/intobject.c

index 40f38ba343beae94979e489689246f54ab22b914..1d05a631c2a0ecd268900a323419ee1faf984f0f 100644 (file)
@@ -675,15 +675,13 @@ int_lshift(PyIntObject *v, PyIntObject *w)
                        return NULL;
                return PyInt_FromLong(0L);
        }
-       c = a < 0 ? ~a : a;
-       c >>= LONG_BIT - 1 - b;
-       if (c) {
+       c = a << b;
+       if (a != Py_ARITHMETIC_RIGHT_SHIFT(long, c, b)) {
                if (PyErr_Warn(PyExc_DeprecationWarning,
                               "x<<y losing bits or changing sign "
                               "will return a long in Python 2.4 and up") < 0)
                        return NULL;
        }
-       c = (long)((unsigned long)a << b);
        return PyInt_FromLong(c);
 }