summaryrefslogtreecommitdiffstats
path: root/Lib/sre_parse.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-07-31 20:22:19 (GMT)
committerGitHub <noreply@github.com>2019-07-31 20:22:19 (GMT)
commit33b700ba8cbb128519442eeed8c8747ff73f4524 (patch)
tree5043941ed33d983864ec999b3eab28c222e00805 /Lib/sre_parse.py
parent353306137176985f1a2995ff964b0c00eccd1434 (diff)
downloadcpython-33b700ba8cbb128519442eeed8c8747ff73f4524.zip
cpython-33b700ba8cbb128519442eeed8c8747ff73f4524.tar.gz
cpython-33b700ba8cbb128519442eeed8c8747ff73f4524.tar.bz2
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@yannvgn.io>
Diffstat (limited to 'Lib/sre_parse.py')
-rw-r--r--Lib/sre_parse.py8
1 files changed, 1 insertions, 7 deletions
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index a53735b..cb2c4c3 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -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