On Wed, Dec 08, 2004 at 08:24:20PM -0800, Ashley Winters wrote:
> 
> I was working on the (possibly misguided) assumption that there's a
> cost to capturing, and that perhaps agressive capturing isn't worth
> having "on" in a one-liner. Some deep part of my mind remembers $`
> being bad, I think. If there's no consequence to having capture being
> on, then ignoring it is fine. I don't have a problem with that. As I
> said before, <?foo> reads fine to me.

At least in the current implementation of PGE there's not a big
cost to capturing of any sort.  Each capture is held as a pair of
(start,end) offsets into the target string, so there's no string 
copying or other overhead until the captured item is actually
referred to.  It's even easy to determine $` as being the start 
of the string up to the beginning offset of the $0 capture.  (Yes,
the perl 5 docs indicate there's a cost to $` that's incurred for all
regexps in a program once $` is used, but I don't think that will 
translate over to PGE.)

That might change, of course, especially as we add the ability 
to modify the target string in the middle of the match.  But even
then we may be able to keep the offset pairs as a useful optimization.

At the moment the bigger cost is calling the subrule itself -- and
even here it's basically the equivalent of a method or subroutine call
(actually, coroutine calls), since a called rule maintains its own
match state just like any other match.

Pm

Reply via email to