summaryrefslogtreecommitdiffstats
path: root/Objects/intobject.c
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2002-12-30 22:29:22 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2002-12-30 22:29:22 (GMT)
commitc91ed400e053dc9f11dd30c84e2bb611999dce50 (patch)
treef190a1d4d9d3dbdb7d60afda9f7ea643e4f63b1b /Objects/intobject.c
parent83f898c86c5ce68eaddd8f729a67ae2d7d0666ec (diff)
downloadcpython-c91ed400e053dc9f11dd30c84e2bb611999dce50.zip
cpython-c91ed400e053dc9f11dd30c84e2bb611999dce50.tar.gz
cpython-c91ed400e053dc9f11dd30c84e2bb611999dce50.tar.bz2
SF #561244, Micro optimizations
Initialize the small integers and __builtins__ in startup. This removes some if conditions. Change XDECREF to DECREF for values which shouldn't be NULL.
Diffstat (limited to 'Objects/intobject.c')
-rw-r--r--Objects/intobject.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c
index 19d18d3..10587ac 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -78,7 +78,7 @@ fill_free_list(void)
#define NSMALLPOSINTS 100
#endif
#ifndef NSMALLNEGINTS
-#define NSMALLNEGINTS 1
+#define NSMALLNEGINTS 5
#endif
#if NSMALLNEGINTS + NSMALLPOSINTS > 0
/* References to small integers are saved in this array so that they
@@ -97,8 +97,8 @@ PyInt_FromLong(long ival)
{
register PyIntObject *v;
#if NSMALLNEGINTS + NSMALLPOSINTS > 0
- if (-NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS &&
- (v = small_ints[ival + NSMALLNEGINTS]) != NULL) {
+ if (-NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS) {
+ v = small_ints[ival + NSMALLNEGINTS];
Py_INCREF(v);
#ifdef COUNT_ALLOCS
if (ival >= 0)
@@ -118,13 +118,6 @@ PyInt_FromLong(long ival)
free_list = (PyIntObject *)v->ob_type;
PyObject_INIT(v, &PyInt_Type);
v->ob_ival = ival;
-#if NSMALLNEGINTS + NSMALLPOSINTS > 0
- if (-NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS) {
- /* save this one for a following allocation */
- Py_INCREF(v);
- small_ints[ival + NSMALLNEGINTS] = v;
- }
-#endif
return (PyObject *) v;
}
@@ -945,6 +938,26 @@ PyTypeObject PyInt_Type = {
(freefunc)int_free, /* tp_free */
};
+int
+PyInt_Init(void)
+{
+ PyIntObject *v;
+ int ival;
+#if NSMALLNEGINTS + NSMALLPOSINTS > 0
+ for (ival = -NSMALLNEGINTS; ival < NSMALLPOSINTS; ival++) {
+ if ((free_list = fill_free_list()) == NULL)
+ return 0;
+ /* PyObject_New is inlined */
+ v = free_list;
+ free_list = (PyIntObject *)v->ob_type;
+ PyObject_INIT(v, &PyInt_Type);
+ v->ob_ival = ival;
+ small_ints[ival + NSMALLNEGINTS] = v;
+ }
+#endif
+ return 1;
+}
+
void
PyInt_Fini(void)
{