mirror of
https://github.com/python/cpython.git
synced 2025-09-21 08:00:37 +00:00
Issue #22510: Get rid of little overhead of testing re.DEBUG flag.
This commit is contained in:
parent
d034ece5b3
commit
4d75a01798
1 changed files with 5 additions and 7 deletions
12
Lib/re.py
12
Lib/re.py
|
@ -273,12 +273,10 @@ _pattern_type = type(sre_compile.compile("", 0))
|
||||||
_MAXCACHE = 512
|
_MAXCACHE = 512
|
||||||
def _compile(pattern, flags):
|
def _compile(pattern, flags):
|
||||||
# internal: compile pattern
|
# internal: compile pattern
|
||||||
bypass_cache = flags & DEBUG
|
try:
|
||||||
if not bypass_cache:
|
return _cache[type(pattern), pattern, flags]
|
||||||
try:
|
except KeyError:
|
||||||
return _cache[type(pattern), pattern, flags]
|
pass
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
if isinstance(pattern, _pattern_type):
|
if isinstance(pattern, _pattern_type):
|
||||||
if flags:
|
if flags:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
@ -287,7 +285,7 @@ def _compile(pattern, flags):
|
||||||
if not sre_compile.isstring(pattern):
|
if not sre_compile.isstring(pattern):
|
||||||
raise TypeError("first argument must be string or compiled pattern")
|
raise TypeError("first argument must be string or compiled pattern")
|
||||||
p = sre_compile.compile(pattern, flags)
|
p = sre_compile.compile(pattern, flags)
|
||||||
if not bypass_cache:
|
if not (flags & DEBUG):
|
||||||
if len(_cache) >= _MAXCACHE:
|
if len(_cache) >= _MAXCACHE:
|
||||||
_cache.clear()
|
_cache.clear()
|
||||||
_cache[type(pattern), pattern, flags] = p
|
_cache[type(pattern), pattern, flags] = p
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue