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

View file

@ -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):