[Python-checkins] cpython (merge 3.6 -> default): merge

raymond.hettinger python-checkins at python.org
Sun Sep 18 23:17:57 EDT 2016


https://hg.python.org/cpython/rev/e932a915cf2b
changeset: 103945:e932a915cf2b
parent: 103943:82bc4da1ffef
parent: 103944:88110cfbf4dc
user: Raymond Hettinger <python at rcn.com>
date: Sun Sep 18 20:17:51 2016 -0700
summary:
 merge
files:
 Lib/re.py | 15 ++++-----------
 1 files changed, 4 insertions(+), 11 deletions(-)
diff --git a/Lib/re.py b/Lib/re.py
--- a/Lib/re.py
+++ b/Lib/re.py
@@ -122,6 +122,7 @@
 import enum
 import sre_compile
 import sre_parse
+import functools
 try:
 import _locale
 except ImportError:
@@ -234,7 +235,7 @@
 def purge():
 "Clear the regular expression caches"
 _cache.clear()
- _cache_repl.clear()
+ _compile_repl.cache_clear()
 
 def template(pattern, flags=0):
 "Compile a template pattern, returning a pattern object"
@@ -278,7 +279,6 @@
 # internals
 
 _cache = {}
-_cache_repl = {}
 
 _pattern_type = type(sre_compile.compile("", 0))
 
@@ -311,17 +311,10 @@
 _cache[type(pattern), pattern, flags] = p, loc
 return p
 
+ at functools.lru_cache(_MAXCACHE)
 def _compile_repl(repl, pattern):
 # internal: compile replacement pattern
- try:
- return _cache_repl[repl, pattern]
- except KeyError:
- pass
- p = sre_parse.parse_template(repl, pattern)
- if len(_cache_repl) >= _MAXCACHE:
- _cache_repl.clear()
- _cache_repl[repl, pattern] = p
- return p
+ return sre_parse.parse_template(repl, pattern)
 
 def _expand(pattern, match, template):
 # internal: match.expand implementation hook
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /