[Python-checkins] CVS: python/dist/src/Objects dictobject.c,2.88,2.89

Tim Peters tim_one@users.sourceforge.net
Thu, 17 May 2001 15:25:36 -0700


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

Modified Files:
	dictobject.c 
Log Message:
Speed dictresize by collapsing its two passes into one; the reason given
in the comments for using two passes was bogus, as the only object that
can get decref'ed due to the copy is the dummy key, and decref'ing dummy
can't have side effects (for one thing, dummy is immortal!  for another,
it's a string object, not a potentially dangerous user-defined object).


Index: dictobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v
retrieving revision 2.88
retrieving revision 2.89
diff -C2 -r2.88 -r2.89
*** dictobject.c	2001/05/13 06:43:53	2.88
--- dictobject.c	2001/05/17 22:25:34	2.89
***************
*** 397,410 ****
  	mp->ma_used = 0;
  
! 	/* Make two passes, so we can avoid decrefs
! 	   (and possible side effects) till the table is copied */
  	for (i = 0, ep = oldtable; i < oldsize; i++, ep++) {
! 		if (ep->me_value != NULL)
! 			insertdict(mp,ep->me_key,ep->me_hash,ep->me_value);
! 	}
! 	for (i = 0, ep = oldtable; i < oldsize; i++, ep++) {
! 		if (ep->me_value == NULL) {
! 			Py_XDECREF(ep->me_key);
  		}
  	}
  
--- 397,411 ----
  	mp->ma_used = 0;
  
! 	/* Copy the data over; this is refcount-neutral for active entries;
! 	   dummy entries aren't copied over, of course */
  	for (i = 0, ep = oldtable; i < oldsize; i++, ep++) {
! 		if (ep->me_value != NULL)	/* active entry */
! 			insertdict(mp, ep->me_key, ep->me_hash, ep->me_value);
! 
! 		else if (ep->me_key != NULL) {	/* dummy entry */
! 			assert(ep->me_key == dummy);
! 			Py_DECREF(ep->me_key);
  		}
+ 		/* else key == value == NULL:  nothing to do */
  	}