From: Serhiy Storchaka Date: Sat, 16 Mar 2013 20:53:48 +0000 (+0200) Subject: Issue #16564: Fixed a performance regression relative to Python 3.1 in the X-Git-Tag: v3.3.1rc1~42 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=969ff726420b108ba98d4616ec3e99a24ea5776a;p=python Issue #16564: Fixed a performance regression relative to Python 3.1 in the caching of compiled regular expressions. --- 969ff726420b108ba98d4616ec3e99a24ea5776a diff --cc Lib/re.py index 952b60f45b,b9106061c8..fcea190d33 --- a/Lib/re.py +++ b/Lib/re.py @@@ -259,11 -257,19 +259,18 @@@ def escape(pattern) # -------------------------------------------------------------------- # internals + _cache = {} + _cache_repl = {} + _pattern_type = type(sre_compile.compile("", 0)) - @functools.lru_cache(maxsize=512, typed=True) + _MAXCACHE = 512 - def _compile(pattern, flags): # internal: compile pattern + try: + return _cache[type(pattern), pattern, flags] + except KeyError: + pass if isinstance(pattern, _pattern_type): if flags: raise ValueError(