Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3563153

Browse files
committed
Reduce the size of the _PyLong_DigitValue table.
1 parent 1467ac8 commit 3563153

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

Include/longobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);
4141
#endif
4242

4343
/* For use by intobject.c only */
44-
PyAPI_DATA(int) _PyLong_DigitValue[256];
44+
PyAPI_DATA(unsigned char) _PyLong_DigitValue[256];
4545

4646
/* _PyLong_AsScaledDouble returns a double x and an exponent e such that
4747
the true value is approximately equal to x * 2**(SHIFT*e). e is >= 0.

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ What's New in Python 3.1 alpha 0
1212
Core and Builtins
1313
-----------------
1414

15+
- The internal table, _PyLong_DigitValue, is now an array of unsigned chars
16+
instead of ints (reducing its size from 4 to 8 times thereby reducing
17+
Python's overall memory).
18+
1519
- Issue #1180193: When importing a module from a .pyc (or .pyo) file with
1620
an existing .py counterpart, override the co_filename attributes of all
1721
code objects if the original filename is obsolete (which can happen if the

Objects/longobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ _PyLong_Format(PyObject *aa, int base)
16461646
* Note that when converting a base B string, a char c is a legitimate
16471647
* base B digit iff _PyLong_DigitValue[Py_CHARPyLong_MASK(c)] < B.
16481648
*/
1649-
int _PyLong_DigitValue[256] = {
1649+
unsigned char _PyLong_DigitValue[256] = {
16501650
37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
16511651
37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
16521652
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)
17101710
bits_in_accum = 0;
17111711
pdigit = z->ob_digit;
17121712
while (--p >= start) {
1713-
int k = _PyLong_DigitValue[Py_CHARMASK(*p)];
1713+
int k = (int)_PyLong_DigitValue[Py_CHARMASK(*p)];
17141714
assert(k >= 0 && k < base);
17151715
accum |= (twodigits)(k << bits_in_accum);
17161716
bits_in_accum += bits_per_char;
@@ -1926,7 +1926,7 @@ digit beyond the first.
19261926
c = (digit)_PyLong_DigitValue[Py_CHARMASK(*str++)];
19271927
for (i = 1; i < convwidth && str != scan; ++i, ++str) {
19281928
c = (twodigits)(c * base +
1929-
_PyLong_DigitValue[Py_CHARMASK(*str)]);
1929+
(int)_PyLong_DigitValue[Py_CHARMASK(*str)]);
19301930
assert(c < PyLong_BASE);
19311931
}
19321932

0 commit comments

Comments
 (0)