diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-03-11 07:01:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-11 07:01:58 (GMT) |
commit | 39441fce0218a3f51a80cf17aa179a32651a02f6 (patch) | |
tree | df0c5f53240f95493f53a3aef69975f414b62520 | |
parent | 720a4b69c6b66ae5d6f447d5814bd204170c94b3 (diff) | |
download | cpython-39441fce0218a3f51a80cf17aa179a32651a02f6.zip cpython-39441fce0218a3f51a80cf17aa179a32651a02f6.tar.gz cpython-39441fce0218a3f51a80cf17aa179a32651a02f6.tar.bz2 |
bpo-32338: OrderedDict import is no longer needed in re. (GH-4891)
(cherry picked from commit b931bd0a2fe7e9293339019352baf3317166b769)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
-rw-r--r-- | Lib/re.py | 13 |
1 files changed, 4 insertions, 9 deletions
@@ -128,12 +128,6 @@ try: except ImportError: _locale = None -# try _collections first to reduce startup cost -try: - from _collections import OrderedDict -except ImportError: - from collections import OrderedDict - # public symbols __all__ = [ @@ -271,7 +265,7 @@ Match = type(sre_compile.compile('', 0).match('')) # -------------------------------------------------------------------- # internals -_cache = OrderedDict() +_cache = {} # ordered! _MAXCACHE = 512 def _compile(pattern, flags): @@ -292,9 +286,10 @@ def _compile(pattern, flags): p = sre_compile.compile(pattern, flags) if not (flags & DEBUG): if len(_cache) >= _MAXCACHE: + # Drop the oldest item try: - _cache.popitem(last=False) - except KeyError: + del _cache[next(iter(_cache))] + except (StopIteration, RuntimeError, KeyError): pass _cache[type(pattern), pattern, flags] = p return p |