[Python-Dev] Broken strptime in Python 2.3a1 & CVS

Guido van Rossum guido@python.org
Tue, 14 Jan 2003 19:56:06 -0500


> I expect it would be better for strptime to maintain its own internal cache
> mapping format strings to compiled regexps (as a dict, indexed by format
> strings).  Dict lookup is cheap.  In most programs, this dict will remain
> empty.  In most of the rest, it will have one entry.  *Some* joker will feed
> it an unbounded number of distinct format strings, though, so blow the cache
> away if it gets "too big":
> 
>     regexp = cache.get(fmtstring)
>     if regexp is None:
>         regexp = compile_the_regexp(fmtstring)
>         if len(cache) > 30:  # whatever
>             cache.clear()
>         cache[fmtstring] = regexp
> 
> Then you're robust against all comers (it's also thread-safe).

Yes.  I think that Brett mentioned that the compilation is
locale-aware, so it should at least fetch the relevant locale settings
and blow away the cache if the locale has changed.

--Guido van Rossum (home page: http://www.python.org/~guido/)