[Python-checkins] python/dist/src/Objects listobject.c,2.121,2.122

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Thu, 18 Jul 2002 19:33:10 -0700


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

Modified Files:
	listobject.c 
Log Message:
Cleanup:  Define one internal utility for reversing a list slice, and
use that everywhere.


Index: listobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v
retrieving revision 2.121
retrieving revision 2.122
diff -C2 -d -r2.121 -r2.122
*** listobject.c	17 Jul 2002 16:30:38 -0000	2.121
--- listobject.c	19 Jul 2002 02:33:08 -0000	2.122
***************
*** 740,743 ****
--- 740,759 ----
  }
  
+ /* Reverse a slice of a list in place, from lo up to (exclusive) hi. */
+ static void
+ reverse_slice(PyObject **lo, PyObject **hi)
+ {
+ 	assert(lo && hi);
+ 
+ 	--hi;
+ 	while (lo < hi) {
+ 		PyObject *t = *lo;
+ 		*lo = *hi;
+ 		*hi = t;
+ 		++lo;
+ 		--hi;
+ 	}
+ }
+ 
  /* New quicksort implementation for arrays of object pointers.
     Thanks to discussions with Tim Peters. */
***************
*** 1027,1038 ****
  	if (hi - r <= MAXMERGE) {
  		/* Reverse the reversed prefix, then insert the tail */
! 		PyObject **originalr = r;
! 		l = lo;
! 		do {
! 			--r;
! 			tmp = *l; *l = *r; *r = tmp;
! 			++l;
! 		} while (l < r);
! 		return binarysort(lo, hi, originalr, compare);
  	}
  
--- 1043,1048 ----
  	if (hi - r <= MAXMERGE) {
  		/* Reverse the reversed prefix, then insert the tail */
! 		reverse_slice(lo, r);
! 		return binarysort(lo, hi, r, compare);
  	}
  
***************
*** 1322,1347 ****
  }
  
- static void
- _listreverse(PyListObject *self)
- {
- 	register PyObject **p, **q;
- 	register PyObject *tmp;
- 	
- 	if (self->ob_size > 1) {
- 		for (p = self->ob_item, q = self->ob_item + self->ob_size - 1;
- 		     p < q;
- 		     p++, q--)
- 		{
- 			tmp = *p;
- 			*p = *q;
- 			*q = tmp;
- 		}
- 	}
- }
- 
  static PyObject *
  listreverse(PyListObject *self)
  {
! 	_listreverse(self);
  	Py_INCREF(Py_None);
  	return Py_None;
--- 1332,1339 ----
  }
  
  static PyObject *
  listreverse(PyListObject *self)
  {
! 	reverse_slice(self->ob_item, self->ob_item + self->ob_size);
  	Py_INCREF(Py_None);
  	return Py_None;
***************
*** 1355,1359 ****
  		return -1;
  	}
! 	_listreverse((PyListObject *)v);
  	return 0;
  }
--- 1347,1351 ----
  		return -1;
  	}
! 	listreverse((PyListObject *)v);
  	return 0;
  }