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-701e127f7d892909a58c6f3333e23588ccef9e22.tar.gz
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
* Then var's value is matched to it and matching part removed.
*/
if (val) {
- bool match_at_left;
+ char *exp_exp_word;
char *loc;
- scan_t scan = pick_scan(exp_op, *exp_word, &match_at_left);
+ unsigned scan_flags = pick_scan(exp_op, *exp_word);
if (exp_op == *exp_word) /* ## or %% */
exp_word++;
val = to_be_freed = xstrdup(val);
- {
- char *exp_exp_word = expand_pseudo_dquoted(exp_word);
- if (exp_exp_word)
- exp_word = exp_exp_word;
- loc = scan(to_be_freed, exp_word, match_at_left);
- //bb_error_msg("op:%c str:'%s' pat:'%s' res:'%s'",
- // exp_op, to_be_freed, exp_word, loc);
- free(exp_exp_word);
- }
+ exp_exp_word = expand_pseudo_dquoted(exp_word);
+ if (exp_exp_word)
+ exp_word = exp_exp_word;
+ loc = scan_and_match(to_be_freed, exp_word, scan_flags);
+ //bb_error_msg("op:%c str:'%s' pat:'%s' res:'%s'",
+ // exp_op, to_be_freed, exp_word, loc);
+ free(exp_exp_word);
if (loc) { /* match was found */
- if (match_at_left) /* # or ## */
+ if (scan_flags & SCAN_MATCH_LEFT_HALF) /* # or ## */
val = loc;
else /* % or %% */
*loc = '\0';