Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5aeee1ac
Commit
5aeee1ac
authored
Sep 18, 2016
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #28193: Use lru_cache in the re module.
parent
ad429eac
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
11 deletions
+4
-11
Lib/re.py
Lib/re.py
+4
-11
No files found.
Lib/re.py
View file @
5aeee1ac
...
...
@@ -122,6 +122,7 @@ This module also defines an exception 'error'.
import
enum
import
sre_compile
import
sre_parse
import
functools
try
:
import
_locale
except
ImportError
:
...
...
@@ -234,7 +235,7 @@ def compile(pattern, flags=0):
def
purge
():
"Clear the regular expression caches"
_cache
.
clear
()
_c
ache_repl
.
clear
()
_c
ompile_repl
.
cache_
clear
()
def
template
(
pattern
,
flags
=
0
):
"Compile a template pattern, returning a pattern object"
...
...
@@ -278,7 +279,6 @@ def escape(pattern):
# internals
_cache
=
{}
_cache_repl
=
{}
_pattern_type
=
type
(
sre_compile
.
compile
(
""
,
0
))
...
...
@@ -311,17 +311,10 @@ def _compile(pattern, flags):
_cache
[
type
(
pattern
),
pattern
,
flags
]
=
p
,
loc
return
p
@
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment