diff options
author | Alin Mr <almr.oss@outlook.com> | 2021-07-28 11:40:01 +0300 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-10-09 02:15:52 +0200 |
commit | 21e8dbfd9d11a461ed7f91b495fa39d8a9131b28 (patch) | |
tree | f7e2a43aa315aed066f13e2e09f5b52cdb0b5985 | |
parent | 94eb1c4dc6556932e1a12a0ce7734512ac95985e (diff) | |
download | busybox-w32-21e8dbfd9d11a461ed7f91b495fa39d8a9131b28.tar.gz busybox-w32-21e8dbfd9d11a461ed7f91b495fa39d8a9131b28.tar.bz2 busybox-w32-21e8dbfd9d11a461ed7f91b495fa39d8a9131b28.zip |
ash.c: speedup ${s:} substring (no quotes)
This trivial patch makes ${s:...} at least as fast as ${s#??..}
in simple tests. It's probably faster for longer substrings,
but then one wouldn't use ${s#"1024???s"} anyway -
one would switch away from sh.
function old new delta
subevalvar 1457 1503 +46
Signed-off-by: Alin Mr <almr.oss@outlook.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/shell/ash.c b/shell/ash.c index 7b85981ec..e8ec0b1a6 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -7185,14 +7185,19 @@ subevalvar(char *start, char *str, int strloc, | |||
7185 | if ((unsigned)len > (orig_len - pos)) | 7185 | if ((unsigned)len > (orig_len - pos)) |
7186 | len = orig_len - pos; | 7186 | len = orig_len - pos; |
7187 | 7187 | ||
7188 | for (vstr = startp; pos; vstr++, pos--) { | 7188 | if (!quotes) { |
7189 | if (quotes && (unsigned char)*vstr == CTLESC) | 7189 | loc = mempcpy(startp, startp + pos, len); |
7190 | } else { | ||
7191 | for (vstr = startp; pos != 0; pos--) { | ||
7192 | if ((unsigned char)*vstr == CTLESC) | ||
7193 | vstr++; | ||
7190 | vstr++; | 7194 | vstr++; |
7191 | } | 7195 | } |
7192 | for (loc = startp; len; len--) { | 7196 | for (loc = startp; len != 0; len--) { |
7193 | if (quotes && (unsigned char)*vstr == CTLESC) | 7197 | if ((unsigned char)*vstr == CTLESC) |
7198 | *loc++ = *vstr++; | ||
7194 | *loc++ = *vstr++; | 7199 | *loc++ = *vstr++; |
7195 | *loc++ = *vstr++; | 7200 | } |
7196 | } | 7201 | } |
7197 | *loc = '\0'; | 7202 | *loc = '\0'; |
7198 | goto out; | 7203 | goto out; |