From c2a0b524d7bff72d0a0f59269fd7dbf194acfd53 Mon Sep 17 00:00:00 2001 From: Cody Maloney Date: Wed, 26 Nov 2025 14:20:19 -0800 Subject: [PATCH 1/3] gh-141968: Use take_byes in re._compiler Removes a copy going from bytearray to bytes. --- Lib/re/_compiler.py | 2 +- .../next/Library/2025-11-26-14-20-10.gh-issue-141968.W139Pv.rst | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2025-11-26-14-20-10.gh-issue-141968.W139Pv.rst diff --git a/Lib/re/_compiler.py b/Lib/re/_compiler.py index 20dd561d1c1520..c2ca8e25abe34d 100644 --- a/Lib/re/_compiler.py +++ b/Lib/re/_compiler.py @@ -375,7 +375,7 @@ def _optimize_charset(charset, iscased=None, fixup=None, fixes=None): # less significant byte is a bit index in the chunk (just like the # CHARSET matching). - charmap = bytes(charmap) # should be hashable + charmap = charmap.take_bytes() # should be hashable comps = {} mapping = bytearray(256) block = 0 diff --git a/Misc/NEWS.d/next/Library/2025-11-26-14-20-10.gh-issue-141968.W139Pv.rst b/Misc/NEWS.d/next/Library/2025-11-26-14-20-10.gh-issue-141968.W139Pv.rst new file mode 100644 index 00000000000000..1d072590883d1c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-11-26-14-20-10.gh-issue-141968.W139Pv.rst @@ -0,0 +1,2 @@ +Remove data copy from :mod:`re` compilation of regexes with large charsets +by using :func:`bytearray.take_byes`. From 4c2924f4a86ac17710d8d92e0e5203555abb1023 Mon Sep 17 00:00:00 2001 From: Cody Maloney Date: Wed, 26 Nov 2025 15:10:02 -0800 Subject: [PATCH 2/3] Fix typo in blurb --- .../next/Library/2025-11-26-14-20-10.gh-issue-141968.W139Pv.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-11-26-14-20-10.gh-issue-141968.W139Pv.rst b/Misc/NEWS.d/next/Library/2025-11-26-14-20-10.gh-issue-141968.W139Pv.rst index 1d072590883d1c..b55eb2c5ac2449 100644 --- a/Misc/NEWS.d/next/Library/2025-11-26-14-20-10.gh-issue-141968.W139Pv.rst +++ b/Misc/NEWS.d/next/Library/2025-11-26-14-20-10.gh-issue-141968.W139Pv.rst @@ -1,2 +1,2 @@ Remove data copy from :mod:`re` compilation of regexes with large charsets -by using :func:`bytearray.take_byes`. +by using :func:`bytearray.take_bytes`. From 9fb0725bd9ce8a4e0b1700ec19317ec096109b6b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 28 Nov 2025 18:18:20 +0100 Subject: [PATCH 3/3] Update Misc/NEWS.d/next/Library/2025-11-26-14-20-10.gh-issue-141968.W139Pv.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- .../next/Library/2025-11-26-14-20-10.gh-issue-141968.W139Pv.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-11-26-14-20-10.gh-issue-141968.W139Pv.rst b/Misc/NEWS.d/next/Library/2025-11-26-14-20-10.gh-issue-141968.W139Pv.rst index b55eb2c5ac2449..c5375707814ff5 100644 --- a/Misc/NEWS.d/next/Library/2025-11-26-14-20-10.gh-issue-141968.W139Pv.rst +++ b/Misc/NEWS.d/next/Library/2025-11-26-14-20-10.gh-issue-141968.W139Pv.rst @@ -1,2 +1,2 @@ Remove data copy from :mod:`re` compilation of regexes with large charsets -by using :func:`bytearray.take_bytes`. +by using :meth:`bytearray.take_bytes`.