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>
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:
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}.