[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH] ash.c: speedup ${s:} substring (no quotes)
From: Alin Mr <almr.oss () outlook ! com>
Date: 2021-07-28 8:40:01
Message-ID: AM8PR08MB5795E83F9C27A6F4E668D02DF7EA9 () AM8PR08MB5795 ! eurprd08 ! prod ! outlook ! com
[Download RAW message or body]
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.
memmove could possibly be replaced by memcpy.
I haven't found much on testing (or contributing for that matter) on the
website or in the source. `make test` produces a bunch of failures on
master anyway, so I'm not sure how to test new code.
Signed-off-by: Alin Mr <almr.oss@outlook.com>
---
shell/ash.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/shell/ash.c b/shell/ash.c
index b5947147a..df4d82e39 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -7198,14 +7198,25 @@ 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)
- vstr++;
+ if (! quotes) {
+ vstr = startp + pos;
+ pos = 0;
+ } else {
+ for (vstr = startp; pos; vstr++, pos--) {
+ if ((unsigned char)*vstr == CTLESC)
+ vstr++;
+ }
}
- for (loc = startp; len; len--) {
- if (quotes && (unsigned char)*vstr == CTLESC)
+ if (! quotes) {
+ memmove (loc, vstr, len);
+ loc = startp + len;
+ len = 0;
+ } else {
+ for (loc = startp; len; len--) {
+ if ((unsigned char)*vstr == CTLESC)
+ *loc++ = *vstr++;
*loc++ = *vstr++;
- *loc++ = *vstr++;
+ }
}
*loc = '\0';
goto out;
--
2.30.2
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic