[Python-checkins] GH-98766: Modest speed-up from ChainMap.__iter__ (GH-98946)

rhettinger webhook-mailer at python.org
Tue Nov 1 00:44:46 EDT 2022


https://github.com/python/cpython/commit/f5afb7f2331efa8f64080576a75517c3a96442b9
commit: f5afb7f2331efa8f64080576a75517c3a96442b9
branch: main
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2022-10-31T23:44:40-05:00
summary:

GH-98766: Modest speed-up from ChainMap.__iter__ (GH-98946)

files:
M Lib/collections/__init__.py

diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index 58607874be93..f07ee143a5af 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -1011,8 +1011,8 @@ def __len__(self):
 
     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):



More information about the Python-checkins mailing list