Reduce the size of the _PyLong_DigitValue table.

This commit is contained in:
Raymond Hettinger 2009-01-09 03:58:09 +00:00
parent 1467ac8e54
commit 3563153793
3 changed files with 8 additions and 4 deletions

View File

@ -41,7 +41,7 @@ PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);
#endif #endif
/* For use by intobject.c only */ /* For use by intobject.c only */
PyAPI_DATA(int) _PyLong_DigitValue[256]; PyAPI_DATA(unsigned char) _PyLong_DigitValue[256];
/* _PyLong_AsScaledDouble returns a double x and an exponent e such that /* _PyLong_AsScaledDouble returns a double x and an exponent e such that
the true value is approximately equal to x * 2**(SHIFT*e). e is >= 0. the true value is approximately equal to x * 2**(SHIFT*e). e is >= 0.

View File

@ -12,6 +12,10 @@ What's New in Python 3.1 alpha 0
Core and Builtins Core and Builtins
----------------- -----------------
- The internal table, _PyLong_DigitValue, is now an array of unsigned chars
instead of ints (reducing its size from 4 to 8 times thereby reducing
Python's overall memory).
- Issue #1180193: When importing a module from a .pyc (or .pyo) file with - Issue #1180193: When importing a module from a .pyc (or .pyo) file with
an existing .py counterpart, override the co_filename attributes of all an existing .py counterpart, override the co_filename attributes of all
code objects if the original filename is obsolete (which can happen if the code objects if the original filename is obsolete (which can happen if the

View File

@ -1646,7 +1646,7 @@ _PyLong_Format(PyObject *aa, int base)
* Note that when converting a base B string, a char c is a legitimate * Note that when converting a base B string, a char c is a legitimate
* base B digit iff _PyLong_DigitValue[Py_CHARPyLong_MASK(c)] < B. * base B digit iff _PyLong_DigitValue[Py_CHARPyLong_MASK(c)] < B.
*/ */
int _PyLong_DigitValue[256] = { unsigned char _PyLong_DigitValue[256] = {
37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
@ -1710,7 +1710,7 @@ long_from_binary_base(char **str, int base)
bits_in_accum = 0; bits_in_accum = 0;
pdigit = z->ob_digit; pdigit = z->ob_digit;
while (--p >= start) { while (--p >= start) {
int k = _PyLong_DigitValue[Py_CHARMASK(*p)]; int k = (int)_PyLong_DigitValue[Py_CHARMASK(*p)];
assert(k >= 0 && k < base); assert(k >= 0 && k < base);
accum |= (twodigits)(k << bits_in_accum); accum |= (twodigits)(k << bits_in_accum);
bits_in_accum += bits_per_char; bits_in_accum += bits_per_char;
@ -1926,7 +1926,7 @@ digit beyond the first.
c = (digit)_PyLong_DigitValue[Py_CHARMASK(*str++)]; c = (digit)_PyLong_DigitValue[Py_CHARMASK(*str++)];
for (i = 1; i < convwidth && str != scan; ++i, ++str) { for (i = 1; i < convwidth && str != scan; ++i, ++str) {
c = (twodigits)(c * base + c = (twodigits)(c * base +
_PyLong_DigitValue[Py_CHARMASK(*str)]); (int)_PyLong_DigitValue[Py_CHARMASK(*str)]);
assert(c < PyLong_BASE); assert(c < PyLong_BASE);
} }