gh-100792: Make `email.message.Message.__contains__` twice as fast (#100793)

This commit is contained in:
Nikita Sobolev 2023-01-08 00:26:05 +03:00 committed by GitHub
parent 47b9f83a83
commit 6746135b07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -448,7 +448,11 @@ class Message:
self._headers = newheaders
def __contains__(self, name):
return name.lower() in [k.lower() for k, v in self._headers]
name_lower = name.lower()
for k, v in self._headers:
if name_lower == k.lower():
return True
return False
def __iter__(self):
for field, value in self._headers:

View File

@ -0,0 +1 @@
Make :meth:`email.message.Message.__contains__` twice as fast.