bpo-37723: Fix performance regression on regular expression parsing. (GH-15030)
authoryannvgn <hi@yannvgn.io>
Wed, 31 Jul 2019 18:50:39 +0000 (20:50 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 31 Jul 2019 18:50:39 +0000 (21:50 +0300)
Improve performance of sre_parse._uniq function.

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 84c912573e7f5443bdb63ffaecc1a645f4fc4c43..83119168e6376ee83bb41f7b75d2c9a0cd3058d7 100644 (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
index 9ff74ec0cca13e637ac9ddf30170bcc3f5711751..6463b535e17ce9526e47c1f80bae2229893bac06 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1708,6 +1708,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