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>
This commit is contained in:
parent
94eb1c4dc6
commit
21e8dbfd9d
17
shell/ash.c
17
shell/ash.c
@ -7185,14 +7185,19 @@ subevalvar(char *start, char *str, int strloc,
|
|||||||
if ((unsigned)len > (orig_len - pos))
|
if ((unsigned)len > (orig_len - pos))
|
||||||
len = orig_len - pos;
|
len = orig_len - pos;
|
||||||
|
|
||||||
for (vstr = startp; pos; vstr++, pos--) {
|
if (!quotes) {
|
||||||
if (quotes && (unsigned char)*vstr == CTLESC)
|
loc = mempcpy(startp, startp + pos, len);
|
||||||
|
} else {
|
||||||
|
for (vstr = startp; pos != 0; pos--) {
|
||||||
|
if ((unsigned char)*vstr == CTLESC)
|
||||||
|
vstr++;
|
||||||
vstr++;
|
vstr++;
|
||||||
}
|
}
|
||||||
for (loc = startp; len; len--) {
|
for (loc = startp; len != 0; len--) {
|
||||||
if (quotes && (unsigned char)*vstr == CTLESC)
|
if ((unsigned char)*vstr == CTLESC)
|
||||||
|
*loc++ = *vstr++;
|
||||||
*loc++ = *vstr++;
|
*loc++ = *vstr++;
|
||||||
*loc++ = *vstr++;
|
}
|
||||||
}
|
}
|
||||||
*loc = '\0';
|
*loc = '\0';
|
||||||
goto out;
|
goto out;
|
||||||
|
Loading…
Reference in New Issue
Block a user