]> granicus.if.org Git - python/commit
Optimize dictionary iterators.
authorRaymond Hettinger <python@rcn.com>
Thu, 18 Mar 2004 02:41:19 +0000 (02:41 +0000)
committerRaymond Hettinger <python@rcn.com>
Thu, 18 Mar 2004 02:41:19 +0000 (02:41 +0000)
commit019a148c7221efa8292dad547170282799b23e13
treec9941c3334dbe02e304a65b53c77e1b2fac70746
parent65d63424b4b1d705830f582f2a43634377f59433
Optimize dictionary iterators.

* Split into three separate types that share everything except the
  code for iternext.  Saves run time decision making and allows
  each iternext function to be specialized.

* Inlined PyDict_Next().  In addition to saving a function call, this
  allows a redundant test to be eliminated and further specialization
  of the code for the unique needs of each iterator type.

* Created a reusable result tuple for iteritems().  Saves the malloc
  time for tuples when the previous result was not kept by client code
  (this is the typical use case for iteritems).  If the client code
  does keep the reference, then a new tuple is created.

Results in a 20% to 30% speedup depending on the size and sparsity
of the dictionary.
Objects/dictobject.c