]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-141968: Use take_bytes in re._compiler (#141995)
authorCody Maloney <cmaloney@users.noreply.github.com>
Fri, 28 Nov 2025 17:46:10 +0000 (09:46 -0800)
committerGitHub <noreply@github.com>
Fri, 28 Nov 2025 17:46:10 +0000 (17:46 +0000)
Removes a copy going from bytearray to bytes.

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Lib/re/_compiler.py
Misc/NEWS.d/next/Library/2025-11-26-14-20-10.gh-issue-141968.W139Pv.rst [new file with mode: 0644]

index 20dd561d1c1520fe0ece07bcd92e7e24a297f779..c2ca8e25abe34d3d0c4ef714e7e8e090a341dc35 100644 (file)
@@ -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 (file)
index 0000000..c537570
--- /dev/null
@@ -0,0 +1,2 @@
+Remove data copy from :mod:`re` compilation of regexes with large charsets
+by using :meth:`bytearray.take_bytes`.