[Python-checkins] r73696 - python/branches/release31-maint/Lib/collections.py
raymond.hettinger
python-checkins at python.org
Mon Jun 29 20:34:46 CEST 2009
Author: raymond.hettinger
Date: Mon Jun 29 20:34:46 2009
New Revision: 73696
Log:
Issue 6370: Performance issue with collections.Counter().
Modified:
python/branches/release31-maint/Lib/collections.py
Modified: python/branches/release31-maint/Lib/collections.py
==============================================================================
--- python/branches/release31-maint/Lib/collections.py (original)
+++ python/branches/release31-maint/Lib/collections.py Mon Jun 29 20:34:46 2009
@@ -421,13 +421,15 @@
if iterable is not None:
if isinstance(iterable, Mapping):
if self:
+ self_get = self.get
for elem, count in iterable.items():
- self[elem] += count
+ self[elem] = count + self_get(elem, 0)
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] = 1 + self_get(elem, 0)
if kwds:
self.update(kwds)
More information about the Python-checkins
mailing list