mirror of https://github.com/python/cpython
Issue 6370: Performance issue with collections.Counter().
This commit is contained in:
parent
34116922d3
commit
5dfc7f9fc8
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue