diff options
author | Raymond Hettinger <python@rcn.com> | 2009-06-29 18:30:43 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-06-29 18:30:43 (GMT) |
commit | f909202c11e0a304486c9fb71458e19a598d10c0 (patch) | |
tree | 4763ca3929423601d4ce777a5af2f0f57cd59c4f /Lib/collections.py | |
parent | 0156f9177167fdb2397dc79e995efdc572d2f812 (diff) | |
download | cpython-f909202c11e0a304486c9fb71458e19a598d10c0.zip cpython-f909202c11e0a304486c9fb71458e19a598d10c0.tar.gz cpython-f909202c11e0a304486c9fb71458e19a598d10c0.tar.bz2 |
Issue 6370: Performance issue with collections.Counter().
Diffstat (limited to 'Lib/collections.py')
-rw-r--r-- | Lib/collections.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/collections.py b/Lib/collections.py index bd5d3e8..f255919 100644 --- a/Lib/collections.py +++ b/Lib/collections.py @@ -421,13 +421,15 @@ class Counter(dict): 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) |