Skip to content

Commit 9f55551

Browse files
yannvgnserhiy-storchaka
authored andcommitted
bpo-37723: Fix performance regression on regular expression parsing. (GH-15030)
Improve performance of sre_parse._uniq function.
1 parent 1b29af8 commit 9f55551

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

Lib/sre_parse.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,7 @@ def _escape(source, escape, state):
430430
raise source.error("bad escape %s" % escape, len(escape))
431431

432432
def _uniq(items):
433-
if len(set(items)) == len(items):
434-
return items
435-
newitems = []
436-
for item in items:
437-
if item not in newitems:
438-
newitems.append(item)
439-
return newitems
433+
return list(dict.fromkeys(items))
440434

441435
def _parse_sub(source, state, verbose, nested):
442436
# parse an alternation: a|b|c

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,7 @@ Michael Urman
17081708
Hector Urtubia
17091709
Lukas Vacek
17101710
Ville Vainio
1711+
Yann Vaginay
17111712
Andi Vajda
17121713
Case Van Horsen
17131714
John Mark Vandenberg
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix performance regression on regular expression parsing with huge
2+
character sets. Patch by Yann Vaginay.

0 commit comments

Comments
 (0)