From: Cody Maloney Date: Fri, 28 Nov 2025 17:46:10 +0000 (-0800) Subject: gh-141968: Use take_bytes in re._compiler (#141995) X-Git-Tag: v3.15.0a3~257 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3001464248edfba76fc23d4a8107dc24f2807d46;p=thirdparty%2FPython%2Fcpython.git gh-141968: Use take_bytes in re._compiler (#141995) Removes a copy going from bytearray to bytes. Co-authored-by: Victor Stinner Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- diff --git a/Lib/re/_compiler.py b/Lib/re/_compiler.py index 20dd561d1c15..c2ca8e25abe3 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 000000000000..c5375707814f --- /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 :meth:`bytearray.take_bytes`.