[xpressive&regex&spirit] Can previous regex be cached?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[xpressive&regex&spirit] Can previous regex be cached?

l_d_allan
<alert comment=<boost newbie">

Xpressive provides a "tips n tricks" to:
Compiling a regex (dynamic or static) is more expensive than executing
a match or search. If you have the option, prefer to compile a pattern
into a basic_regex<> object once and reuse it rather than recreating
it over and over.

Would it be feasible/advantageous for the regex-related libraries to
automagically to "cache" the immediately previous regex compilation?
(or provide as an option)

I've seen code that had the same regex being compiled inside a loop,
which I suppose would really diminish performance. Perhaps this could
be detected, and the user/developer "protected from themselves" ...
and/or perhaps informed that this is happening?

Could there be a "helper" class that somehow or other allowed the last
"n" regexes to be cached? (btw .... what is the plural of regex ....
regexen?  regices?)

</alert>


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [xpressive&regex&spirit] Can previous regex be cached?

John Maddock
> Would it be feasible/advantageous for the regex-related libraries to
> automagically to "cache" the immediately previous regex compilation?
> (or provide as an option)

Feasable, yes, in the sense that anything is feasable, probably not
advantageous though, it depends entirely on how it's used.

> I've seen code that had the same regex being compiled inside a loop,
> which I suppose would really diminish performance. Perhaps this could
> be detected, and the user/developer "protected from themselves" ...
> and/or perhaps informed that this is happening?

Nod, that's a very bad idea, but I don't see how we can protect against it.

> Could there be a "helper" class that somehow or other allowed the last
> "n" regexes to be cached? (btw .... what is the plural of regex ....
> regexen?  regices?)

You mean a generic cache object?  It's been asked for before, and should be
an entirely separate facility from regex/xpressive/spirit.  Boost.Regex does
actually use one internally to cache some locale-related structures (which
rairly if ever change in typical useage).  See
boost/regex/pending/object_cache.hpp if you want the dirty details, or want
to borrow the code.

John.

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users