diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-06 12:24:58 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-06 12:24:58 +0000 |
commit | b1d11bf45ec55d469f47c1341d593fdae790bb6a (patch) | |
tree | 1451bb52ef01ba105e7a33315010042f77f793ea | |
parent | d0b4a8c285c6fd79b397dd22131ef3a66d8f3d7f (diff) | |
download | busybox-w32-b1d11bf45ec55d469f47c1341d593fdae790bb6a.tar.gz busybox-w32-b1d11bf45ec55d469f47c1341d593fdae790bb6a.tar.bz2 busybox-w32-b1d11bf45ec55d469f47c1341d593fdae790bb6a.zip |
hush: more efficient filtering of "safe" arithmetic
function old new delta
expand_variables 2170 2147 -23
-rw-r--r-- | shell/hush.c | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/shell/hush.c b/shell/hush.c index 3aae7d7c1..e86f0d22f 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -1782,24 +1782,15 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask) | |||
1782 | debug_printf_subst("ARITH '%s' first_ch %x\n", arg, first_ch); | 1782 | debug_printf_subst("ARITH '%s' first_ch %x\n", arg, first_ch); |
1783 | 1783 | ||
1784 | /* Optional: skip expansion if expr is simple ("a + 3", "i++" etc) */ | 1784 | /* Optional: skip expansion if expr is simple ("a + 3", "i++" etc) */ |
1785 | exp_str = arg; | 1785 | exp_str = NULL; |
1786 | while (1) { | 1786 | if (strchr(arg, '$') != NULL |
1787 | unsigned char c = *exp_str++; | 1787 | #if ENABLE_HUSH_TICK |
1788 | if (c == '\0') { | 1788 | || strchr(arg, '`') != NULL |
1789 | exp_str = NULL; | 1789 | #endif |
1790 | goto skip_expand; | 1790 | ) { |
1791 | } | 1791 | /* We need to expand. Example: |
1792 | if (isdigit(c)) | 1792 | * echo $(($a + `echo 1`)) $((1 + $((2)) )) |
1793 | continue; | 1793 | */ |
1794 | if (strchr(" \t+-*/%<>()_", c) != NULL) | ||
1795 | continue; | ||
1796 | c |= 0x20; /* tolower */ | ||
1797 | if (c >= 'a' && c <= 'z') | ||
1798 | continue; | ||
1799 | break; | ||
1800 | } | ||
1801 | /* We need to expand. Example: "echo $(($a + 1)) $((1 + $((2)) ))" */ | ||
1802 | { | ||
1803 | struct in_str input; | 1794 | struct in_str input; |
1804 | o_string dest = NULL_O_STRING; | 1795 | o_string dest = NULL_O_STRING; |
1805 | 1796 | ||
@@ -1810,7 +1801,6 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask) | |||
1810 | //bb_error_msg("'%s' -> '%s'", dest.data, exp_str); | 1801 | //bb_error_msg("'%s' -> '%s'", dest.data, exp_str); |
1811 | o_free(&dest); | 1802 | o_free(&dest); |
1812 | } | 1803 | } |
1813 | skip_expand: | ||
1814 | hooks.lookupvar = get_local_var_value; | 1804 | hooks.lookupvar = get_local_var_value; |
1815 | hooks.setvar = arith_set_local_var; | 1805 | hooks.setvar = arith_set_local_var; |
1816 | hooks.endofname = endofname; | 1806 | hooks.endofname = endofname; |