in reply to How are we lazy?

In interation 2, Lazy only has to "forwardtrack" 4 times and then matches and doesn't even look at the last 2000 characters of the string.

I'm disappointed that Lazy doesn't seem to be optimized very well, with the simplest of "forwardtracking" to find the closing " going much, much slower than matching [^"]+"

Replies are listed 'Best First'.
(Ovid) RE: RE: How are we lazy?
by Ovid (Cardinal) on Jul 19, 2000 at 01:06 UTC
    Thank you! I don't know why I didn't think of forward tracking. Looking at all of the other results in light of this, they make perfect sense (even though I thought they were a little odd before). Tomorrow, you will get a ++ vote from me :)

    Actually, I think lazy has to be slower than a negated character class. Basically, either greedy or lazy quantifiers using the dot metacharacter are forced to back- or forwardtrack. That nasty little dot will match with anything that it can get its grubby little hands on and will cause the regex to "overshoot" which greatly increases the amount of necessary backtracking or forwardtracking.

    With the character class, Perl creates what amounts to a seive. Characters which match (or don't match, in the case of a negated character class) pass through the seive. When we get a non-allowed character, it stops, period. There is no "tracking" which occurs afterwards to clean up.