From 3563153793623f693b8cd5697cd8a2ae6094d240 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 9 Jan 2009 03:58:09 +0000 Subject: [PATCH] Reduce the size of the _PyLong_DigitValue table. --- Include/longobject.h | 2 +- Misc/NEWS | 4 ++++ Objects/longobject.c | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Include/longobject.h b/Include/longobject.h index 73ca9511964..7adf9c735e9 100644 --- a/Include/longobject.h +++ b/Include/longobject.h @@ -41,7 +41,7 @@ PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *); #endif /* 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 the true value is approximately equal to x * 2**(SHIFT*e). e is >= 0. diff --git a/Misc/NEWS b/Misc/NEWS index 685033c469b..0ce7f7ad9c0 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,10 @@ What's New in Python 3.1 alpha 0 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 an existing .py counterpart, override the co_filename attributes of all code objects if the original filename is obsolete (which can happen if the diff --git a/Objects/longobject.c b/Objects/longobject.c index 362d0ad2399..9993d103ea2 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -1646,7 +1646,7 @@ _PyLong_Format(PyObject *aa, int base) * 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. */ -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, @@ -1710,7 +1710,7 @@ long_from_binary_base(char **str, int base) bits_in_accum = 0; pdigit = z->ob_digit; while (--p >= start) { - int k = _PyLong_DigitValue[Py_CHARMASK(*p)]; + int k = (int)_PyLong_DigitValue[Py_CHARMASK(*p)]; assert(k >= 0 && k < base); accum |= (twodigits)(k << bits_in_accum); bits_in_accum += bits_per_char; @@ -1926,7 +1926,7 @@ digit beyond the first. c = (digit)_PyLong_DigitValue[Py_CHARMASK(*str++)]; for (i = 1; i < convwidth && str != scan; ++i, ++str) { c = (twodigits)(c * base + - _PyLong_DigitValue[Py_CHARMASK(*str)]); + (int)_PyLong_DigitValue[Py_CHARMASK(*str)]); assert(c < PyLong_BASE); }