[Python-checkins] python/dist/src/Objects listobject.c, 2.185, 2.186 tupleobject.c, 2.82, 2.83

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Mon Mar 8 02:25:07 EST 2004


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11822/Objects

Modified Files:
	listobject.c tupleobject.c 
Log Message:
Optimize tuple_slice() and make further improvements to list_slice()
and list.extend().  Factoring the inner loops to remove the constant
structure references and fixed offsets gives speedups ranging from
20% to 30%.



Index: listobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v
retrieving revision 2.185
retrieving revision 2.186
diff -C2 -d -r2.185 -r2.186
*** listobject.c	8 Mar 2004 05:56:15 -0000	2.185
--- listobject.c	8 Mar 2004 07:25:04 -0000	2.186
***************
*** 343,346 ****
--- 343,347 ----
  {
  	PyListObject *np;
+ 	PyObject **src, **dest;
  	int i, len;
  	if (ilow < 0)
***************
*** 357,364 ****
  		return NULL;
  
  	for (i = 0; i < len; i++) {
! 		PyObject *v = a->ob_item[i+ilow];
  		Py_INCREF(v);
! 		np->ob_item[i] = v;
  	}
  	return (PyObject *)np;
--- 358,367 ----
  		return NULL;
  
+ 	src = a->ob_item + ilow;
+ 	dest = np->ob_item;
  	for (i = 0; i < len; i++) {
! 		PyObject *v = src[i];
  		Py_INCREF(v);
! 		dest[i] = v;
  	}
  	return (PyObject *)np;
***************
*** 647,650 ****
--- 650,654 ----
  	int blen;
  	register int i;
+ 	PyObject **src, **dest;
  
  	if (PyObject_Size(b) == 0) {
***************
*** 679,695 ****
  
  	/* populate the end of self with b's items */
! 	if (PyList_Check(b)) {
! 		for (i = 0; i < blen; i++) {
! 			PyObject *o = PyList_GET_ITEM(b, i);
! 			Py_INCREF(o);
! 			PyList_SET_ITEM(self, i+selflen, o);
! 		}
! 	} else {
  		assert (PyTuple_Check(b));
! 		for (i = 0; i < blen; i++) {
! 			PyObject *o = PyTuple_GET_ITEM(b, i);
! 			Py_INCREF(o);
! 			PyList_SET_ITEM(self, i+selflen, o);
! 		}
  	}
  	Py_DECREF(b);
--- 683,697 ----
  
  	/* populate the end of self with b's items */
! 	if (PyList_Check(b)) 
! 		src = ((PyListObject *)b)->ob_item;
! 	else {
  		assert (PyTuple_Check(b));
! 		src = ((PyTupleObject *)b)->ob_item;
! 	}
! 	dest = self->ob_item + selflen;
! 	for (i = 0; i < blen; i++) {
! 		PyObject *o = src[i];
! 		Py_INCREF(o);
! 		dest[i] = o;
  	}
  	Py_DECREF(b);

Index: tupleobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/tupleobject.c,v
retrieving revision 2.82
retrieving revision 2.83
diff -C2 -d -r2.82 -r2.83
*** tupleobject.c	12 Oct 2003 18:24:33 -0000	2.82
--- tupleobject.c	8 Mar 2004 07:25:04 -0000	2.83
***************
*** 307,311 ****
--- 307,313 ----
  {
  	register PyTupleObject *np;
+ 	PyObject **src, **dest;
  	register int i;
+ 	int len;
  	if (ilow < 0)
  		ilow = 0;
***************
*** 318,328 ****
  		return (PyObject *)a;
  	}
! 	np = (PyTupleObject *)PyTuple_New(ihigh - ilow);
  	if (np == NULL)
  		return NULL;
! 	for (i = ilow; i < ihigh; i++) {
! 		PyObject *v = a->ob_item[i];
  		Py_INCREF(v);
! 		np->ob_item[i - ilow] = v;
  	}
  	return (PyObject *)np;
--- 320,333 ----
  		return (PyObject *)a;
  	}
! 	len = ihigh - ilow;
! 	np = (PyTupleObject *)PyTuple_New(len);
  	if (np == NULL)
  		return NULL;
! 	src = a->ob_item + ilow;
! 	dest = np->ob_item;
! 	for (i = 0; i < len; i++) {
! 		PyObject *v = src[i];
  		Py_INCREF(v);
! 		dest[i] = v;
  	}
  	return (PyObject *)np;




More information about the Python-checkins mailing list