]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-37723: Fix performance regression on regular expression parsing. (GH-15030)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 31 Jul 2019 20:22:19 +0000 (13:22 -0700)
committerGitHub <noreply@github.com>
Wed, 31 Jul 2019 20:22:19 +0000 (13:22 -0700)
Improve performance of sre_parse._uniq function.
(cherry picked from commit 9f55551f3df238e58315e724e50cb0d574d75b94)

Co-authored-by: yannvgn <hi@yannvgn.io>
Lib/sre_parse.py
Misc/ACKS
Misc/NEWS.d/next/Library/2019-07-31-16-49-01.bpo-37723.zq6tw8.rst [new file with mode: 0644]

index a53735b07ded420ca2bc9fa636f40b9eb2241500..cb2c4c3281c9c3e5e5affecf0bb65c9373aed3df 100644 (file)
@@ -406,13 +406,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
index 1b54d7ef7f183745546dc693cf93adadc1588a1b..29b6690f2174a7fab4e3d7afe967ff33658d8cfd 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1672,6 +1672,7 @@ Michael Urman
 Hector Urtubia
 Lukas Vacek
 Ville Vainio
+Yann Vaginay
 Andi Vajda
 Case Van Horsen
 John Mark Vandenberg
diff --git a/Misc/NEWS.d/next/Library/2019-07-31-16-49-01.bpo-37723.zq6tw8.rst b/Misc/NEWS.d/next/Library/2019-07-31-16-49-01.bpo-37723.zq6tw8.rst
new file mode 100644 (file)
index 0000000..65507bd
--- /dev/null
@@ -0,0 +1,2 @@
+Fix performance regression on regular expression parsing with huge
+character sets. Patch by Yann Vaginay.
\ No newline at end of file