From fe612489c044a0e076ac227af60b56fa4c1963e9 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Fri, 6 Jan 2023 14:05:40 +0300 Subject: [PATCH 1/2] gh-100792: Make `email.message.Message.__contains__` twice as fast --- Lib/email/message.py | 6 +++++- .../Library/2023-01-06-14-05-15.gh-issue-100792.CEOJth.rst | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2023-01-06-14-05-15.gh-issue-100792.CEOJth.rst diff --git a/Lib/email/message.py b/Lib/email/message.py index 65fda507251ce3..b540c33984a753 100644 --- a/Lib/email/message.py +++ b/Lib/email/message.py @@ -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: diff --git a/Misc/NEWS.d/next/Library/2023-01-06-14-05-15.gh-issue-100792.CEOJth.rst b/Misc/NEWS.d/next/Library/2023-01-06-14-05-15.gh-issue-100792.CEOJth.rst new file mode 100644 index 00000000000000..fc73c973dbe1ee --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-01-06-14-05-15.gh-issue-100792.CEOJth.rst @@ -0,0 +1 @@ +Make ``email.message.Message.__contains__`` twice as fast. From d2d0c76d6061fd270c514b4a6402788c2d3ab9ec Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Sat, 7 Jan 2023 20:22:05 +0300 Subject: [PATCH 2/2] Update Misc/NEWS.d/next/Library/2023-01-06-14-05-15.gh-issue-100792.CEOJth.rst Co-authored-by: Alex Waygood --- .../next/Library/2023-01-06-14-05-15.gh-issue-100792.CEOJth.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-01-06-14-05-15.gh-issue-100792.CEOJth.rst b/Misc/NEWS.d/next/Library/2023-01-06-14-05-15.gh-issue-100792.CEOJth.rst index fc73c973dbe1ee..5966bc1e605158 100644 --- a/Misc/NEWS.d/next/Library/2023-01-06-14-05-15.gh-issue-100792.CEOJth.rst +++ b/Misc/NEWS.d/next/Library/2023-01-06-14-05-15.gh-issue-100792.CEOJth.rst @@ -1 +1 @@ -Make ``email.message.Message.__contains__`` twice as fast. +Make :meth:`email.message.Message.__contains__` twice as fast.