• Raymond Hettinger's avatar
    Optimize dictionary iterators. · 019a148c
    Raymond Hettinger authored
    * 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.
    019a148c
dictobject.c 56.5 KB