diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-07-31 20:22:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-31 20:22:09 (GMT) |
commit | 77fcccb5321137456549b7f55b819f2c8a4c78a4 (patch) | |
tree | e8809c2cf1b74a11c0b4d335a99820ee1fb3fc6a | |
parent | 29a3a33d99dae0106c6af9d0fd75a11bef26d15c (diff) | |
download | cpython-77fcccb5321137456549b7f55b819f2c8a4c78a4.zip cpython-77fcccb5321137456549b7f55b819f2c8a4c78a4.tar.gz cpython-77fcccb5321137456549b7f55b819f2c8a4c78a4.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>
-rw-r--r-- | Lib/sre_parse.py | 8 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2019-07-31-16-49-01.bpo-37723.zq6tw8.rst | 2 |
3 files changed, 4 insertions, 7 deletions
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py index 84c9125..8311916 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 @@ -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 0000000..65507bd --- /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 |