summaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenys Vlasenko2018-07-17 14:33:19 +0200
committerDenys Vlasenko2018-07-17 14:33:19 +0200
commit0d2e0de42bab54c31ba37f1c6fd10dcdc7008ccf (patch)
tree9c84b82f6bb324a685ac8270aa44230121e7c7bb /shell/hush.c
parentb762c784caa78877a9949224af425e52db237beb (diff)
downloadbusybox-0d2e0de42bab54c31ba37f1c6fd10dcdc7008ccf.zip
busybox-0d2e0de42bab54c31ba37f1c6fd10dcdc7008ccf.tar.gz
hush: faster/smaller code to check for presense of multiple chars in string
Go over the string only once. function old new delta encode_then_expand_string 126 105 -21 encode_then_expand_vararg 443 399 -44 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-65) Total: -65 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 415993e..238f997 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -5730,14 +5730,17 @@ static char *encode_then_expand_string(const char *str)
char *exp_str;
struct in_str input;
o_string dest = NULL_O_STRING;
+ const char *cp;
- if (!strchr(str, '$')
- && !strchr(str, '\\')
+ cp = str;
+ for (;;) {
+ if (!*cp) return NULL; /* string has no special chars */
+ if (*cp == '$') break;
+ if (*cp == '\\') break;
#if ENABLE_HUSH_TICK
- && !strchr(str, '`')
+ if (*cp == '`') break;
#endif
- ) {
- return NULL;
+ cp++;
}
/* We need to expand. Example:
@@ -5768,17 +5771,19 @@ static char *encode_then_expand_vararg(const char *str, int handle_squotes, int
char *exp_str;
struct in_str input;
o_string dest = NULL_O_STRING;
+ const char *cp;
- if (!strchr(str, '$')
- && !strchr(str, '\\')
- && !strchr(str, '\'')
-//todo:better code
- && !strchr(str, '"')
+ cp = str;
+ for (;;) {
+ if (!*cp) return NULL; /* string has no special chars */
+ if (*cp == '$') break;
+ if (*cp == '\\') break;
+ if (*cp == '\'') break;
+ if (*cp == '"') break;
#if ENABLE_HUSH_TICK
- && !strchr(str, '`')
+ if (*cp == '`') break;
#endif
- ) {
- return NULL;
+ cp++;
}
/* Expanding ARG in ${var#ARG}, ${var%ARG}, or ${var/ARG/ARG}.