Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Lib/email/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,11 @@ def __delitem__(self, name):
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:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make ``email.message.Message.__contains__`` twice as fast.