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

Tim Peters tim_one@users.sourceforge.net
Tue, 10 Jul 2001 13:13:46 -0700


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

Modified Files:
      Tag: descr-branch
	dictobject.c 
Log Message:
dict_new() and EMPTY_TO_MINSIZE:  minor performance boost in dict_new,
by exploiting that tp_alloc guarantees to zero out the dictobject struct.
So dict_new can skipping doing that too (for two scalar members, + the
ma_smalltable member consisting of 8 dictentry structs each in turn
containing 3 scalar members).


Index: dictobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v
retrieving revision 2.80.2.19
retrieving revision 2.80.2.20
diff -C2 -r2.80.2.19 -r2.80.2.20
*** dictobject.c	2001/07/09 03:28:36	2.80.2.19
--- dictobject.c	2001/07/10 20:13:44	2.80.2.20
***************
*** 127,137 ****
  #endif
  
! /* Set PyDictObject* mp to empty but w/ PyDict_MINSIZE slots, using
!    ma_smalltable. */
! #define EMPTY_TO_MINSIZE(mp) do { 					\
! 	memset((mp)->ma_smalltable, 0, sizeof((mp)->ma_smalltable));	\
  	(mp)->ma_table = (mp)->ma_smalltable;				\
  	(mp)->ma_mask = PyDict_MINSIZE - 1;				\
  	(mp)->ma_used = (mp)->ma_fill = 0;				\
      } while(0)
  
--- 127,148 ----
  #endif
  
! /* Initialization macros.
!    There are two ways to create a dict:  PyDict_New() is the main C API
!    function, and the tp_new slot maps to dict_new().  In the latter case we
!    can save a little time over what PyDict_New does because it's guaranteed
!    that the PyDictObject struct is already zeroed out.
!    Everyone except dict_new() should use EMPTY_TO_MINSIZE (unless they have
!    an excellent reason not to).
! */
! 
! #define INIT_NONZERO_DICT_SLOTS(mp) do {				\
  	(mp)->ma_table = (mp)->ma_smalltable;				\
  	(mp)->ma_mask = PyDict_MINSIZE - 1;				\
+     } while(0)
+ 
+ #define EMPTY_TO_MINSIZE(mp) do {					\
+ 	memset((mp)->ma_smalltable, 0, sizeof((mp)->ma_smalltable));	\
  	(mp)->ma_used = (mp)->ma_fill = 0;				\
+ 	INIT_NONZERO_DICT_SLOTS(mp);					\
      } while(0)
  
***************
*** 1681,1685 ****
  	if (self != NULL) {
  		PyDictObject *d = (PyDictObject *)self;
! 		EMPTY_TO_MINSIZE(d);
  		d->ma_lookup = lookdict_string;
  #ifdef SHOW_CONVERSION_COUNTS
--- 1692,1698 ----
  	if (self != NULL) {
  		PyDictObject *d = (PyDictObject *)self;
! 		/* It's guaranteed that tp->alloc zeroed out the struct. */
! 		assert(d->ma_table == NULL && d->ma_fill == 0 && d->ma_used == 0);
! 		INIT_NONZERO_DICT_SLOTS(d);
  		d->ma_lookup = lookdict_string;
  #ifdef SHOW_CONVERSION_COUNTS