]> granicus.if.org Git - python/commitdiff
Issue #16564: Fixed a performance regression relative to Python 3.1 in the
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 16 Mar 2013 20:53:48 +0000 (22:53 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 16 Mar 2013 20:53:48 +0000 (22:53 +0200)
caching of compiled regular expressions.

1  2 
Lib/re.py
Misc/NEWS

diff --cc Lib/re.py
index 952b60f45bfe8390152c392f7f844df538f9a491,b9106061c85a67c8eb543aa808bbbef55bb4fa55..fcea190d3377863844f1fc93fea1083a5a9373ca
+++ 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(
diff --cc Misc/NEWS
Simple merge