mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
Issue 13227: Option to make the lru_cache() type specific (suggested by Andrew Koenig).
This commit is contained in:
parent
e3455c026a
commit
cd9fdfd652
5 changed files with 49 additions and 12 deletions
|
@ -207,7 +207,7 @@ def compile(pattern, flags=0):
|
|||
|
||||
def purge():
|
||||
"Clear the regular expression caches"
|
||||
_compile_typed.cache_clear()
|
||||
_compile.cache_clear()
|
||||
_compile_repl.cache_clear()
|
||||
|
||||
def template(pattern, flags=0):
|
||||
|
@ -253,11 +253,8 @@ def escape(pattern):
|
|||
|
||||
_pattern_type = type(sre_compile.compile("", 0))
|
||||
|
||||
@functools.lru_cache(maxsize=500, typed=True)
|
||||
def _compile(pattern, flags):
|
||||
return _compile_typed(type(pattern), pattern, flags)
|
||||
|
||||
@functools.lru_cache(maxsize=500)
|
||||
def _compile_typed(text_bytes_type, pattern, flags):
|
||||
# internal: compile pattern
|
||||
if isinstance(pattern, _pattern_type):
|
||||
if flags:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue