diff -r 3e6792af95f0 Objects/longobject.c --- a/Objects/longobject.c Fri Jun 17 00:01:30 2016 +0200 +++ b/Objects/longobject.c Fri Jun 17 11:37:36 2016 +0300 @@ -667,6 +667,12 @@ sign = -1; i = -i; } + + /* No need to iterate over digits whose bits would be shifted + out of x anyway. + Round upward this way instead of calling ceil, to allow the + expression to be calculated at compile time. */ + i = Py_MIN(i, (sizeof(x) * 8 - 1) / PyLong_SHIFT + 1); while (--i >= 0) { x = (x << PyLong_SHIFT) | v->ob_digit[i]; } @@ -1301,6 +1307,12 @@ sign = -1; i = -i; } + + /* No need to iterate over digits whose bits would be shifted + out of x anyway. + Round upward this way instead of calling ceil, to allow the + expression to be calculated at compile time. */ + i = Py_MIN(i, (sizeof(x) * 8 - 1) / PyLong_SHIFT + 1); while (--i >= 0) { x = (x << PyLong_SHIFT) | v->ob_digit[i]; }