https://github.com/python/cpython/commit/56e190068177855266f32a7efa329d145b279f94
commit: 56e190068177855266f32a7efa329d145b279f94
branch: main
author: Bénédikt Tran <10796600+picn...@users.noreply.github.com>
committer: encukou <encu...@gmail.com>
date: 2025-02-26T13:01:32+01:00
summary:

gh-128982: Substitute regular expression in `http.cookiejar.join_header_words` 
for an efficient alternative (GH-128983)

The function does not anymore rely on a regular expression
to find alphanumeric characters and underscores.

files:
A Misc/NEWS.d/next/Library/2025-01-18-11-40-11.gh-issue-128982.557lS5.rst
M Lib/http/cookiejar.py

diff --git a/Lib/http/cookiejar.py b/Lib/http/cookiejar.py
index fb0fd2e97999af..4ebb1601b4dd82 100644
--- a/Lib/http/cookiejar.py
+++ b/Lib/http/cookiejar.py
@@ -448,7 +448,7 @@ def join_header_words(lists):
         attr = []
         for k, v in pairs:
             if v is not None:
-                if not re.search(r"^\w+$", v):
+                if not v.isalnum() and '_' not in v:
                     v = HEADER_JOIN_ESCAPE_RE.sub(r"\\\1", v)  # escape " and \
                     v = '"%s"' % v
                 k = "%s=%s" % (k, v)
diff --git 
a/Misc/NEWS.d/next/Library/2025-01-18-11-40-11.gh-issue-128982.557lS5.rst 
b/Misc/NEWS.d/next/Library/2025-01-18-11-40-11.gh-issue-128982.557lS5.rst
new file mode 100644
index 00000000000000..44b7a7b537364c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-18-11-40-11.gh-issue-128982.557lS5.rst
@@ -0,0 +1,2 @@
+Improve the performance of :func:`!http.cookiejar.join_header_words` by up
+to 35%. Patch by Bénédikt Tran.

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to