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

This commit is contained in:
Raymond Hettinger 2022-10-31 23:44:40 -05:00 committed by GitHub
parent 5cf317ade1
commit f5afb7f233
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -1011,8 +1011,8 @@ class ChainMap(_collections_abc.MutableMapping):
def __iter__(self): def __iter__(self):
d = {} d = {}
for mapping in reversed(self.maps): for mapping in map(dict.fromkeys, reversed(self.maps)):
d.update(dict.fromkeys(mapping)) # reuses stored hash values if possible d |= mapping # reuses stored hash values if possible
return iter(d) return iter(d)
def __contains__(self, key): def __contains__(self, key):