]> granicus.if.org Git - python/commitdiff
long_from_binary_base(): Sped this a little by computing the # of bits
authorTim Peters <tim.peters@gmail.com>
Sun, 2 Feb 2003 17:33:53 +0000 (17:33 +0000)
committerTim Peters <tim.peters@gmail.com>
Sun, 2 Feb 2003 17:33:53 +0000 (17:33 +0000)
needed outside the first loop.

Objects/longobject.c

index 92e95f7867de62f52dc22b129a7950048f028273..2ccf414edb5f0052270cb66a3cb6618d1ffe7776 100644 (file)
@@ -1126,15 +1126,15 @@ long_from_binary_base(char **str, int base)
                        k = ch - 'A' + 10;
                if (k < 0 || k >= base)
                        break;
-               n += bits_per_char;
-               if (n < 0) {
-                       PyErr_SetString(PyExc_ValueError,
-                                       "long string too large to convert");
-                       return NULL;
-               }
                ++p;
        }
        *str = p;
+       n = (p - start) * bits_per_char;
+       if (n / bits_per_char != p - start) {
+               PyErr_SetString(PyExc_ValueError,
+                               "long string too large to convert");
+               return NULL;
+       }
        /* n <- # of Python digits needed, = ceiling(n/SHIFT). */
        n = (n + SHIFT - 1) / SHIFT;
        z = _PyLong_New(n);