aboutsummaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-09-04 21:21:07 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-09-04 21:21:07 +0200
commit701e127f7d892909a58c6f3333e23588ccef9e22 (patch)
tree9d756fca6a1ef496dbf02529e090f2f711a6c261 /shell/hush.c
parente298ce69baef029f3951dd1d5ed50fdbc6c55c80 (diff)
downloadbusybox-w32-701e127f7d892909a58c6f3333e23588ccef9e22.tar.gz
busybox-w32-701e127f7d892909a58c6f3333e23588ccef9e22.tar.bz2
busybox-w32-701e127f7d892909a58c6f3333e23588ccef9e22.zip
hush: optimize #[#] and %[%] for speed. size -2 bytes.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/shell/hush.c b/shell/hush.c
index d3dab5863..4f80b7d83 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -2829,23 +2829,21 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg, char
2829 * Then var's value is matched to it and matching part removed. 2829 * Then var's value is matched to it and matching part removed.
2830 */ 2830 */
2831 if (val) { 2831 if (val) {
2832 bool match_at_left; 2832 char *exp_exp_word;
2833 char *loc; 2833 char *loc;
2834 scan_t scan = pick_scan(exp_op, *exp_word, &match_at_left); 2834 unsigned scan_flags = pick_scan(exp_op, *exp_word);
2835 if (exp_op == *exp_word) /* ## or %% */ 2835 if (exp_op == *exp_word) /* ## or %% */
2836 exp_word++; 2836 exp_word++;
2837 val = to_be_freed = xstrdup(val); 2837 val = to_be_freed = xstrdup(val);
2838 { 2838 exp_exp_word = expand_pseudo_dquoted(exp_word);
2839 char *exp_exp_word = expand_pseudo_dquoted(exp_word); 2839 if (exp_exp_word)
2840 if (exp_exp_word) 2840 exp_word = exp_exp_word;
2841 exp_word = exp_exp_word; 2841 loc = scan_and_match(to_be_freed, exp_word, scan_flags);
2842 loc = scan(to_be_freed, exp_word, match_at_left); 2842 //bb_error_msg("op:%c str:'%s' pat:'%s' res:'%s'",
2843 //bb_error_msg("op:%c str:'%s' pat:'%s' res:'%s'", 2843 // exp_op, to_be_freed, exp_word, loc);
2844 // exp_op, to_be_freed, exp_word, loc); 2844 free(exp_exp_word);
2845 free(exp_exp_word);
2846 }
2847 if (loc) { /* match was found */ 2845 if (loc) { /* match was found */
2848 if (match_at_left) /* # or ## */ 2846 if (scan_flags & SCAN_MATCH_LEFT_HALF) /* # or ## */
2849 val = loc; 2847 val = loc;
2850 else /* % or %% */ 2848 else /* % or %% */
2851 *loc = '\0'; 2849 *loc = '\0';