summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlin Mr2021-07-28 11:40:01 +0300
committerDenys Vlasenko2021-10-09 02:15:52 +0200
commit21e8dbfd9d11a461ed7f91b495fa39d8a9131b28 (patch)
treef7e2a43aa315aed066f13e2e09f5b52cdb0b5985
parent94eb1c4dc6556932e1a12a0ce7734512ac95985e (diff)
downloadbusybox-21e8dbfd9d11a461ed7f91b495fa39d8a9131b28.zip
busybox-21e8dbfd9d11a461ed7f91b495fa39d8a9131b28.tar.gz
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.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 7b85981..e8ec0b1 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -7185,14 +7185,19 @@ subevalvar(char *start, char *str, int strloc,
if ((unsigned)len > (orig_len - pos))
len = orig_len - pos;
- for (vstr = startp; pos; vstr++, pos--) {
- if (quotes && (unsigned char)*vstr == CTLESC)
+ if (!quotes) {
+ loc = mempcpy(startp, startp + pos, len);
+ } else {
+ for (vstr = startp; pos != 0; pos--) {
+ if ((unsigned char)*vstr == CTLESC)
+ vstr++;
vstr++;
- }
- for (loc = startp; len; len--) {
- if (quotes && (unsigned char)*vstr == CTLESC)
+ }
+ for (loc = startp; len != 0; len--) {
+ if ((unsigned char)*vstr == CTLESC)
+ *loc++ = *vstr++;
*loc++ = *vstr++;
- *loc++ = *vstr++;
+ }
}
*loc = '\0';
goto out;