hush: more efficient filtering of "safe" arithmetic

function                                             old     new   delta
expand_variables                                    2170    2147     -23
This commit is contained in:
Denis Vlasenko 2009-04-06 12:24:58 +00:00
parent d0b4a8c285
commit b1d11bf45e

View File

@ -1782,24 +1782,15 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask)
debug_printf_subst("ARITH '%s' first_ch %x\n", arg, first_ch); debug_printf_subst("ARITH '%s' first_ch %x\n", arg, first_ch);
/* Optional: skip expansion if expr is simple ("a + 3", "i++" etc) */ /* Optional: skip expansion if expr is simple ("a + 3", "i++" etc) */
exp_str = arg; exp_str = NULL;
while (1) { if (strchr(arg, '$') != NULL
unsigned char c = *exp_str++; #if ENABLE_HUSH_TICK
if (c == '\0') { || strchr(arg, '`') != NULL
exp_str = NULL; #endif
goto skip_expand; ) {
} /* We need to expand. Example:
if (isdigit(c)) * echo $(($a + `echo 1`)) $((1 + $((2)) ))
continue; */
if (strchr(" \t+-*/%<>()_", c) != NULL)
continue;
c |= 0x20; /* tolower */
if (c >= 'a' && c <= 'z')
continue;
break;
}
/* We need to expand. Example: "echo $(($a + 1)) $((1 + $((2)) ))" */
{
struct in_str input; struct in_str input;
o_string dest = NULL_O_STRING; o_string dest = NULL_O_STRING;
@ -1810,7 +1801,6 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask)
//bb_error_msg("'%s' -> '%s'", dest.data, exp_str); //bb_error_msg("'%s' -> '%s'", dest.data, exp_str);
o_free(&dest); o_free(&dest);
} }
skip_expand:
hooks.lookupvar = get_local_var_value; hooks.lookupvar = get_local_var_value;
hooks.setvar = arith_set_local_var; hooks.setvar = arith_set_local_var;
hooks.endofname = endofname; hooks.endofname = endofname;