mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Issue 6370: Performance issue with collections.Counter().
This commit is contained in:
parent
0156f91771
commit
f909202c11
1 changed files with 4 additions and 2 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue