diff options
author | Raymond Hettinger <python@rcn.com> | 2009-06-29 18:34:46 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-06-29 18:34:46 (GMT) |
commit | 77b31ef202359e6f29d261b7dfbb356f36d49123 (patch) | |
tree | ba71ec091b78e3e765dc4b2f54462edf01087070 /Lib/collections.py | |
parent | 2c3de40971b92d9dcd8ebcb24c0bda031b5732be (diff) | |
download | cpython-77b31ef202359e6f29d261b7dfbb356f36d49123.zip cpython-77b31ef202359e6f29d261b7dfbb356f36d49123.tar.gz cpython-77b31ef202359e6f29d261b7dfbb356f36d49123.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) |