[Python-checkins] bpo-37723: Fix performance regression on regular expression parsing. (GH-15030)
Miss Islington (bot)
webhook-mailer at python.org
Wed Jul 31 16:22:39 EDT 2019
https://github.com/python/cpython/commit/77fcccb5321137456549b7f55b819f2c8a4c78a4
commit: 77fcccb5321137456549b7f55b819f2c8a4c78a4
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-07-31T13:22:09-07:00
summary:
bpo-37723: Fix performance regression on regular expression parsing. (GH-15030)
Improve performance of sre_parse._uniq function.
(cherry picked from commit 9f55551f3df238e58315e724e50cb0d574d75b94)
Co-authored-by: yannvgn <hi at yannvgn.io>
files:
A Misc/NEWS.d/next/Library/2019-07-31-16-49-01.bpo-37723.zq6tw8.rst
M Lib/sre_parse.py
M Misc/ACKS
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index 84c912573e7f..83119168e637 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -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
diff --git a/Misc/ACKS b/Misc/ACKS
index 829aa796c847..ad2e0a1996aa 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1702,6 +1702,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
index 000000000000..65507bd0dc91
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-07-31-16-49-01.bpo-37723.zq6tw8.rst
@@ -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
More information about the Python-checkins
mailing list