Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: fix for (#s) and (#e) in param substs



> Just a question - is there any speed penalty in using / instead of # or
> %?

There will be some effect, since there is no optimisation to look for an
initial (#s) or final (#e) in the parameter substitution code, unlike # and
% where the start/end anchor is hard-coded.  I had to think about this...

Ksh form        Form with explicit anchors
${..#..}        ${(S)../(#s)..}
${..##..}       ${../(#s)..}

In the second form in each case, we still advance up the string looking for
matches, so it's slower, particularly for a long test string.  However, the
test will always fail on the first attempt, so it doesn't depend on the
complexity of the pattern after the anchor.

${..%%..}       ${../..(#e)}

Not much difference, since in the former case we march up the string until
we find a match, pretty much as in the second case.

${..%..}        ${(S)../..(#e)}

These could be quite a lot slower with a fixed tail for a long string,
e.g. ${(S)foo/.c(#e)} where $foo is long, since that has to march up the
string to find a match, then shorten from the end (though the latter will
always fail on the second match so isn't really a problem).  But with a
fixed string you wouldn't bother with the (S) parameter flag.

Anyway, I'd be interested to hear if you can notice any difference using /.

It wouldn't be that hard to do special cases.  I don't know if it's worth
it.  I expect these bits are only going to be used by the real zsh nutcases
:-).

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxxx>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070



Messages sorted by: Reverse Date, Date, Thread, Author