Commit b931bd0a authored by Serhiy Storchaka's avatar Serhiy Storchaka Committed by GitHub

bpo-32338: OrderedDict import is no longer needed in re. (#4891)

parent 26c9f565
...@@ -128,12 +128,6 @@ try: ...@@ -128,12 +128,6 @@ try:
except ImportError: except ImportError:
_locale = None _locale = None
# try _collections first to reduce startup cost
try:
from _collections import OrderedDict
except ImportError:
from collections import OrderedDict
# public symbols # public symbols
__all__ = [ __all__ = [
...@@ -271,7 +265,7 @@ Match = type(sre_compile.compile('', 0).match('')) ...@@ -271,7 +265,7 @@ Match = type(sre_compile.compile('', 0).match(''))
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# internals # internals
_cache = OrderedDict() _cache = {} # ordered!
_MAXCACHE = 512 _MAXCACHE = 512
def _compile(pattern, flags): def _compile(pattern, flags):
...@@ -292,9 +286,10 @@ def _compile(pattern, flags): ...@@ -292,9 +286,10 @@ def _compile(pattern, flags):
p = sre_compile.compile(pattern, flags) p = sre_compile.compile(pattern, flags)
if not (flags & DEBUG): if not (flags & DEBUG):
if len(_cache) >= _MAXCACHE: if len(_cache) >= _MAXCACHE:
# Drop the oldest item
try: try:
_cache.popitem(last=False) del _cache[next(iter(_cache))]
except KeyError: except (StopIteration, RuntimeError, KeyError):
pass pass
_cache[type(pattern), pattern, flags] = p _cache[type(pattern), pattern, flags] = p
return p return p
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment