aboutsummaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2021-01-24 01:23:17 -0800
committerGitHub <noreply@github.com>2021-01-24 12:23:17 +0300
commit15bd9efd01e44087664e78bf766865a6d2e06626 (patch)
treefb8e08f13fa8352c0187f235232c3ed03aae9edb /Lib
parentRemove full stop from a bytes-related SyntaxError message (GH-24300) (diff)
downloadcpython-15bd9efd01e44087664e78bf766865a6d2e06626.tar.gz
cpython-15bd9efd01e44087664e78bf766865a6d2e06626.tar.bz2
cpython-15bd9efd01e44087664e78bf766865a6d2e06626.zip
bpo-43014: Improve performance of tokenize.tokenize by 20-30%
Diffstat (limited to 'Lib')
-rw-r--r--Lib/tokenize.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/Lib/tokenize.py b/Lib/tokenize.py
index 1aee21b5e18..42c1f10373d 100644
--- a/Lib/tokenize.py
+++ b/Lib/tokenize.py
@@ -27,6 +27,7 @@ __credits__ = ('GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, '
from builtins import open as _builtin_open
from codecs import lookup, BOM_UTF8
import collections
+import functools
from io import TextIOWrapper
import itertools as _itertools
import re
@@ -95,6 +96,7 @@ def _all_string_prefixes():
result.add(''.join(u))
return result
+@functools.lru_cache
def _compile(expr):
return re.compile(expr, re.UNICODE)