bpo-37723: Fix performance regression on regular expression parsing. (GH-15030)

Improve performance of sre_parse._uniq function.
(cherry picked from commit 9f55551f3d)

Co-authored-by: yannvgn <hi@yannvgn.io>
This commit is contained in:
Miss Islington (bot) 2019-07-31 13:22:09 -07:00 committed by GitHub
parent 29a3a33d99
commit 77fcccb532
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 7 deletions

View file

@ -430,13 +430,7 @@ def _escape(source, escape, state):
raise source.error("bad escape %s" % escape, len(escape))
def _uniq(items):
if len(set(items)) == len(items):
return items
newitems = []
for item in items:
if item not in newitems:
newitems.append(item)
return newitems
return list(dict.fromkeys(items))
def _parse_sub(source, state, verbose, nested):
# parse an alternation: a|b|c

View file

@ -1702,6 +1702,7 @@ Michael Urman
Hector Urtubia
Lukas Vacek
Ville Vainio
Yann Vaginay
Andi Vajda
Case Van Horsen
John Mark Vandenberg

View file

@ -0,0 +1,2 @@
Fix performance regression on regular expression parsing with huge
character sets. Patch by Yann Vaginay.