Skip to content

Commit 3001464

Browse files
cmaloneyvstinnerpicnixz
authored
gh-141968: Use take_bytes in re._compiler (#141995)
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>
1 parent 5ec03cf commit 3001464

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

Lib/re/_compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def _optimize_charset(charset, iscased=None, fixup=None, fixes=None):
375375
# less significant byte is a bit index in the chunk (just like the
376376
# CHARSET matching).
377377

378-
charmap = bytes(charmap) # should be hashable
378+
charmap = charmap.take_bytes() # should be hashable
379379
comps = {}
380380
mapping = bytearray(256)
381381
block = 0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove data copy from :mod:`re` compilation of regexes with large charsets
2+
by using :meth:`bytearray.take_bytes`.

0 commit comments

Comments
 (0)