Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The "small int" optimization is now unconditionally enabled. This
optimization was introduced in Python 1.0.1, and means that :class:`int`
values from -5 through 256 are pre-initialized rather than constructed on
demand. The option was always enabled unless certain never-documented
preprocessor macros were defined to 0 at build time; now it is always
enabled, simplifying the logic. Patch by Greg Price.
11 changes: 2 additions & 9 deletions 11 Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ _Py_IDENTIFIER(big);
PyObject *_PyLong_Zero = NULL;
PyObject *_PyLong_One = NULL;

#if NSMALLNEGINTS + NSMALLPOSINTS > 0
/* Small integers are preallocated in this array so that they
can be shared.
The integers that are preallocated are those in the range
Expand Down Expand Up @@ -77,10 +76,6 @@ maybe_small_long(PyLongObject *v)
}
return v;
}
#else
#define CHECK_SMALL_INT(ival)
#define maybe_small_long(val) (val)
#endif

/* If a freshly-allocated int is already shared, it must
be a small integer, so negating it must go to PyLong_FromLong */
Expand Down Expand Up @@ -5808,7 +5803,6 @@ PyLong_GetInfo(void)
int
_PyLong_Init(void)
{
#if NSMALLNEGINTS + NSMALLPOSINTS > 0
int ival, size;
PyLongObject *v = small_ints;

Expand Down Expand Up @@ -5836,7 +5830,7 @@ _PyLong_Init(void)
Py_SIZE(v) = size;
v->ob_digit[0] = (digit)abs(ival);
}
#endif

_PyLong_Zero = PyLong_FromLong(0);
if (_PyLong_Zero == NULL)
return 0;
Expand All @@ -5862,12 +5856,11 @@ PyLong_Fini(void)
reinitializations will fail. */
Py_CLEAR(_PyLong_One);
Py_CLEAR(_PyLong_Zero);
#if NSMALLNEGINTS + NSMALLPOSINTS > 0

int i;
PyLongObject *v = small_ints;
for (i = 0; i < NSMALLNEGINTS + NSMALLPOSINTS; i++, v++) {
_Py_DEC_REFTOTAL;
_Py_ForgetReference((PyObject*)v);
}
#endif
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.