RE strings (was: Variable Interpolation - status of PEP 215)

Daniel Dittmar daniel.dittmar at sap.com
Fri Jun 21 15:36:49 CEST 2002


>> The implementation could choose to cache the result of re.compile at
>> module level, thus
>> - speeding up the 'naive' re usage
>> - freeing the programmer from doing the caching in code
>
> Any reason the re.match() method could not do the same, internally?

The caching strategies would be different:

using re"...": the compiler would know that there are only x literals in the
module, thus he would store the re.compile results in an array for fast
lookup.

using module re: this requires a dictionary indexed by the patterns. And it
wouldn't be wise to keep all patterns around, so it depends on the locality
of pattern usage how well the cache performs.

Daniel






More information about the Python-list mailing list