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 128
128
except ImportError :
129
129
_locale = None
130
130
131
- # try _collections first to reduce startup cost
132
- try :
133
- from _collections import OrderedDict
134
- except ImportError :
135
- from collections import OrderedDict
136
-
137
131
138
132
# public symbols
139
133
__all__ = [
@@ -271,7 +265,7 @@ def escape(pattern):
271
265
# --------------------------------------------------------------------
272
266
# internals
273
267
274
- _cache = OrderedDict ()
268
+ _cache = {} # ordered!
275
269
276
270
_MAXCACHE = 512
277
271
def _compile (pattern , flags ):
@@ -292,9 +286,10 @@ def _compile(pattern, flags):
292
286
p = sre_compile .compile (pattern , flags )
293
287
if not (flags & DEBUG ):
294
288
if len (_cache ) >= _MAXCACHE :
289
+ # Drop the oldest item
295
290
try :
296
- _cache . popitem ( last = False )
297
- except KeyError :
291
+ del _cache [ next ( iter ( _cache ))]
292
+ except ( StopIteration , RuntimeError , KeyError ) :
298
293
pass
299
294
_cache [type (pattern ), pattern , flags ] = p
300
295
return p
You can’t perform that action at this time.
0 commit comments