Commit 5dfc7f9f authored by Raymond Hettinger's avatar Raymond Hettinger

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

parent 34116922
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment