zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@cambridgesiliconradio.com>
To: zsh-workers@sunsite.auc.dk (Zsh hackers list)
Subject: Re: PATCH: fix for (#s) and (#e) in param substs
Date: Fri, 14 Apr 2000 13:15:00 +0100	[thread overview]
Message-ID: <0FT000MMUA0ZD3@la-la.cambridgesiliconradio.com> (raw)
In-Reply-To: "Your message of Fri, 14 Apr 2000 15:42:05 +0400." <000601bfa606$750527f0$21c9ca95@mow.siemens.ru>

> 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@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


  reply	other threads:[~2000-04-14 12:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-04-14 11:27 Peter Stephenson
2000-04-14 11:42 ` Andrej Borsenkow
2000-04-14 12:15   ` Peter Stephenson [this message]
2000-04-14 12:00 ` Zefram
2000-04-14 13:03   ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0FT000MMUA0ZD3@la-la.cambridgesiliconradio.com \
    --to=pws@cambridgesiliconradio.com \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).