diff options
author | Raymond Hettinger <python@rcn.com> | 2009-06-29 19:10:29 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-06-29 19:10:29 (GMT) |
commit | 5dfc7f9fc8b0a7eda357643234e415ff51e79711 (patch) | |
tree | 561ea0905a46c1d51612dc1135b55ea8fcab8ce3 /Lib/collections.py | |
parent | 34116922d3f775a25394b621846feb58eb15c3a6 (diff) | |
download | cpython-5dfc7f9fc8b0a7eda357643234e415ff51e79711.zip cpython-5dfc7f9fc8b0a7eda357643234e415ff51e79711.tar.gz cpython-5dfc7f9fc8b0a7eda357643234e415ff51e79711.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 1e807af..abf6f89 100644 --- a/Lib/collections.py +++ b/Lib/collections.py @@ -418,13 +418,15 @@ class Counter(dict): 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) |