[Python-checkins] python/dist/src/Objects intobject.c,2.96,2.97 frameobject.c,2.70,2.71

nnorwitz@users.sourceforge.net nnorwitz@users.sourceforge.net
Mon, 30 Dec 2002 14:29:24 -0800


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv12866/Objects

Modified Files:
	intobject.c frameobject.c 
Log Message:
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.


Index: intobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/intobject.c,v
retrieving revision 2.96
retrieving revision 2.97
diff -C2 -d -r2.96 -r2.97
*** intobject.c	30 Dec 2002 20:19:02 -0000	2.96
--- intobject.c	30 Dec 2002 22:29:21 -0000	2.97
***************
*** 79,83 ****
  #endif
  #ifndef NSMALLNEGINTS
! #define NSMALLNEGINTS		1
  #endif
  #if NSMALLNEGINTS + NSMALLPOSINTS > 0
--- 79,83 ----
  #endif
  #ifndef NSMALLNEGINTS
! #define NSMALLNEGINTS		5
  #endif
  #if NSMALLNEGINTS + NSMALLPOSINTS > 0
***************
*** 98,103 ****
  	register PyIntObject *v;
  #if NSMALLNEGINTS + NSMALLPOSINTS > 0
! 	if (-NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS &&
! 	    (v = small_ints[ival + NSMALLNEGINTS]) != NULL) {
  		Py_INCREF(v);
  #ifdef COUNT_ALLOCS
--- 98,103 ----
  	register PyIntObject *v;
  #if NSMALLNEGINTS + NSMALLPOSINTS > 0
! 	if (-NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS) {
! 		v = small_ints[ival + NSMALLNEGINTS];
  		Py_INCREF(v);
  #ifdef COUNT_ALLOCS
***************
*** 119,129 ****
  	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;
  }
--- 119,122 ----
***************
*** 945,948 ****
--- 938,961 ----
  	(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

Index: frameobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/frameobject.c,v
retrieving revision 2.70
retrieving revision 2.71
diff -C2 -d -r2.70 -r2.71
*** frameobject.c	19 Dec 2002 18:16:57 -0000	2.70
--- frameobject.c	30 Dec 2002 22:29:22 -0000	2.71
***************
*** 402,408 ****
  	
  	Py_XDECREF(f->f_back);
! 	Py_XDECREF(f->f_code);
! 	Py_XDECREF(f->f_builtins);
! 	Py_XDECREF(f->f_globals);
  	Py_XDECREF(f->f_locals);
  	Py_XDECREF(f->f_trace);
--- 402,408 ----
  	
  	Py_XDECREF(f->f_back);
! 	Py_DECREF(f->f_code);
! 	Py_DECREF(f->f_builtins);
! 	Py_DECREF(f->f_globals);
  	Py_XDECREF(f->f_locals);
  	Py_XDECREF(f->f_trace);
***************
*** 526,529 ****
--- 526,537 ----
  };
  
+ static PyObject *builtin_object;
+ 
+ int PyFrame_Init()
+ {
+ 	builtin_object = PyString_InternFromString("__builtins__");
+ 	return (builtin_object != NULL);
+ }
+ 
  PyFrameObject *
  PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals, 
***************
*** 531,544 ****
  {
  	PyFrameObject *back = tstate->frame;
- 	static PyObject *builtin_object;
  	PyFrameObject *f;
  	PyObject *builtins;
  	int extras, ncells, nfrees;
  
- 	if (builtin_object == NULL) {
- 		builtin_object = PyString_InternFromString("__builtins__");
- 		if (builtin_object == NULL)
- 			return NULL;
- 	}
  #ifdef Py_DEBUG
  	if (code == NULL || globals == NULL || !PyDict_Check(globals) ||
--- 539,546 ----
***************
*** 803,805 ****
--- 805,809 ----
  	}
  	assert(numfree == 0);
+ 	Py_XDECREF(builtin_object);
+ 	builtin_object = NULL;
  }