File tree Expand file tree Collapse file tree 1 file changed +4
-9
lines changed
Expand file tree Collapse file tree 1 file changed +4
-9
lines changed Original file line number Diff line number Diff line change 128128except ImportError :
129129 _locale = None
130130
131- # try _collections first to reduce startup cost
132- try :
133- from _collections import OrderedDict
134- except ImportError :
135- from collections import OrderedDict
136-
137131
138132# public symbols
139133__all__ = [
@@ -271,7 +265,7 @@ def escape(pattern):
271265# --------------------------------------------------------------------
272266# internals
273267
274- _cache = OrderedDict ()
268+ _cache = {} # ordered!
275269
276270_MAXCACHE = 512
277271def _compile (pattern , flags ):
@@ -292,9 +286,10 @@ def _compile(pattern, flags):
292286 p = sre_compile .compile (pattern , flags )
293287 if not (flags & DEBUG ):
294288 if len (_cache ) >= _MAXCACHE :
289+ # Drop the oldest item
295290 try :
296- _cache . popitem ( last = False )
297- except KeyError :
291+ del _cache [ next ( iter ( _cache ))]
292+ except ( StopIteration , RuntimeError , KeyError ) :
298293 pass
299294 _cache [type (pattern ), pattern , flags ] = p
300295 return p
You can’t perform that action at this time.
0 commit comments