long_from_binary_base(): Sped this a little by computing the # of bits

needed outside the first loop.
This commit is contained in:
Tim Peters 2003-02-02 17:33:53 +00:00
parent 70b02d79f9
commit 1a3b19a6e9
1 changed files with 6 additions and 6 deletions

View File

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