[Python-checkins] r73697 - python/trunk/Lib/collections.py

raymond.hettinger python-checkins at python.org
Mon Jun 29 21:10:29 CEST 2009


Author: raymond.hettinger
Date: Mon Jun 29 21:10:29 2009
New Revision: 73697

Log:
Issue 6370: Performance issue with collections.Counter().

Modified:
   python/trunk/Lib/collections.py

Modified: python/trunk/Lib/collections.py
==============================================================================
--- python/trunk/Lib/collections.py	(original)
+++ python/trunk/Lib/collections.py	Mon Jun 29 21:10:29 2009
@@ -418,13 +418,15 @@
         if iterable is not None:
             if isinstance(iterable, Mapping):
                 if self:
+                    self_get = self.get
                     for elem, count in iterable.iteritems():
-                        self[elem] += count
+                        self[elem] = self_get(elem, 0) + count
                 else:
                     dict.update(self, iterable) # fast path when counter is empty
             else:
+                self_get = self.get
                 for elem in iterable:
-                    self[elem] += 1
+                    self[elem] = self_get(elem, 0) + 1
         if kwds:
             self.update(kwds)
 


More information about the Python-checkins mailing list