summaryrefslogtreecommitdiffstats
path: root/Lib/collections
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2022-11-01 04:44:40 (GMT)
committerGitHub <noreply@github.com>2022-11-01 04:44:40 (GMT)
commitf5afb7f2331efa8f64080576a75517c3a96442b9 (patch)
tree8716a7a22dfe8c1d8bf94855f8fc9ba073a1730e /Lib/collections
parent5cf317ade1e1b26ee02621ed84d29a73181631dc (diff)
downloadcpython-f5afb7f2331efa8f64080576a75517c3a96442b9.zip
cpython-f5afb7f2331efa8f64080576a75517c3a96442b9.tar.gz
cpython-f5afb7f2331efa8f64080576a75517c3a96442b9.tar.bz2
GH-98766: Modest speed-up from ChainMap.__iter__ (GH-98946)
Diffstat (limited to 'Lib/collections')
-rw-r--r--Lib/collections/__init__.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index 5860787..f07ee14 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -1011,8 +1011,8 @@ class ChainMap(_collections_abc.MutableMapping):
def __iter__(self):
d = {}
- for mapping in reversed(self.maps):
- d.update(dict.fromkeys(mapping)) # reuses stored hash values if possible
+ for mapping in map(dict.fromkeys, reversed(self.maps)):
+ d |= mapping # reuses stored hash values if possible
return iter(d)
def __contains__(self, key):