Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: fix for (#s) and (#e) in param substs
- X-seq: zsh-workers 10759
- From: Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx (Zsh hackers list)
- Subject: Re: PATCH: fix for (#s) and (#e) in param substs
- Date: Fri, 14 Apr 2000 13:15:00 +0100
- In-reply-to: "Your message of Fri, 14 Apr 2000 15:42:05 +0400." <000601bfa606$750527f0$21c9ca95@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
> 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