diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-28 15:17:44 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-28 15:17:44 +0000 |
commit | cf22c89f9a7d19166fa038d3bb2bac3011f946fd (patch) | |
tree | eb1def85fdf023d76a2d0e6bdf3a927791658acd | |
parent | 12acec5ad40cba57e621829f7339eeb16d981f9f (diff) | |
download | busybox-w32-cf22c89f9a7d19166fa038d3bb2bac3011f946fd.tar.gz busybox-w32-cf22c89f9a7d19166fa038d3bb2bac3011f946fd.tar.bz2 busybox-w32-cf22c89f9a7d19166fa038d3bb2bac3011f946fd.zip |
hush: in run_list(), some loop_top ops seems to be superfluous.
comment them out. Also, use separate temp variable
for verification loop, helps gcc to optimize better.
function old new delta
run_list 2039 1984 -55
-rw-r--r-- | shell/hush.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/shell/hush.c b/shell/hush.c index 98a69c1b1..ca2a1d21f 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -2016,7 +2016,7 @@ static int run_list(struct pipe *pi) | |||
2016 | char *case_word = NULL; | 2016 | char *case_word = NULL; |
2017 | #endif | 2017 | #endif |
2018 | #if ENABLE_HUSH_LOOPS | 2018 | #if ENABLE_HUSH_LOOPS |
2019 | struct pipe *loop_top; | 2019 | struct pipe *loop_top = loop_top; /* just for compiler */ |
2020 | char *for_varname = NULL; | 2020 | char *for_varname = NULL; |
2021 | char **for_lcur = NULL; | 2021 | char **for_lcur = NULL; |
2022 | char **for_list = NULL; | 2022 | char **for_list = NULL; |
@@ -2024,7 +2024,7 @@ static int run_list(struct pipe *pi) | |||
2024 | smallint flag_goto_looptop = 0; | 2024 | smallint flag_goto_looptop = 0; |
2025 | #endif | 2025 | #endif |
2026 | smallint flag_skip = 1; | 2026 | smallint flag_skip = 1; |
2027 | smalluint rcode = 0; /* probably for gcc only */ | 2027 | smalluint rcode = 0; /* probably just for compiler */ |
2028 | #if ENABLE_HUSH_IF | 2028 | #if ENABLE_HUSH_IF |
2029 | smalluint cond_code = 0; | 2029 | smalluint cond_code = 0; |
2030 | ///experimentally off: last_cond_code seems to be bogus | 2030 | ///experimentally off: last_cond_code seems to be bogus |
@@ -2039,21 +2039,21 @@ static int run_list(struct pipe *pi) | |||
2039 | 2039 | ||
2040 | #if ENABLE_HUSH_LOOPS | 2040 | #if ENABLE_HUSH_LOOPS |
2041 | /* check syntax for "for" */ | 2041 | /* check syntax for "for" */ |
2042 | for (loop_top = pi; loop_top; loop_top = loop_top->next) { | 2042 | for (struct pipe *cpipe = pi; cpipe; cpipe = cpipe->next) { |
2043 | if (loop_top->res_word != RES_FOR && loop_top->res_word != RES_IN) | 2043 | if (cpipe->res_word != RES_FOR && cpipe->res_word != RES_IN) |
2044 | continue; | 2044 | continue; |
2045 | /* current word is FOR or IN (BOLD in comments below) */ | 2045 | /* current word is FOR or IN (BOLD in comments below) */ |
2046 | if (loop_top->next == NULL) { | 2046 | if (cpipe->next == NULL) { |
2047 | syntax("malformed for"); | 2047 | syntax("malformed for"); |
2048 | debug_printf_exec("run_list lvl %d return 1\n", run_list_level); | 2048 | debug_printf_exec("run_list lvl %d return 1\n", run_list_level); |
2049 | return 1; | 2049 | return 1; |
2050 | } | 2050 | } |
2051 | /* "FOR v; do ..." and "for v IN a b; do..." are ok */ | 2051 | /* "FOR v; do ..." and "for v IN a b; do..." are ok */ |
2052 | if (loop_top->next->res_word == RES_DO) | 2052 | if (cpipe->next->res_word == RES_DO) |
2053 | continue; | 2053 | continue; |
2054 | /* next word is not "do". It must be "in" then ("FOR v in ...") */ | 2054 | /* next word is not "do". It must be "in" then ("FOR v in ...") */ |
2055 | if (loop_top->res_word == RES_IN /* "for v IN a b; not_do..."? */ | 2055 | if (cpipe->res_word == RES_IN /* "for v IN a b; not_do..."? */ |
2056 | || loop_top->next->res_word != RES_IN /* FOR v not_do_and_not_in..."? */ | 2056 | || cpipe->next->res_word != RES_IN /* FOR v not_do_and_not_in..."? */ |
2057 | ) { | 2057 | ) { |
2058 | syntax("malformed for"); | 2058 | syntax("malformed for"); |
2059 | debug_printf_exec("run_list lvl %d return 1\n", run_list_level); | 2059 | debug_printf_exec("run_list lvl %d return 1\n", run_list_level); |
@@ -2118,10 +2118,10 @@ static int run_list(struct pipe *pi) | |||
2118 | if (rword == RES_WHILE || rword == RES_UNTIL || rword == RES_FOR) { | 2118 | if (rword == RES_WHILE || rword == RES_UNTIL || rword == RES_FOR) { |
2119 | /* start of a loop: remember it */ | 2119 | /* start of a loop: remember it */ |
2120 | flag_goto_looptop = 0; /* not yet reached final "done" */ | 2120 | flag_goto_looptop = 0; /* not yet reached final "done" */ |
2121 | if (!loop_top) { /* hmm why this check is needed? */ | 2121 | // if (!loop_top) { /* hmm why this check is needed? */ |
2122 | flag_run_loop = 0; /* suppose loop condition is false (for now) */ | 2122 | // flag_run_loop = 0; /* suppose loop condition is false (for now) */ |
2123 | loop_top = pi; /* remember where loop starts */ | 2123 | loop_top = pi; /* remember where loop starts */ |
2124 | } | 2124 | // } |
2125 | } | 2125 | } |
2126 | #endif | 2126 | #endif |
2127 | if (rword == skip_more_for_this_rword && flag_skip) { | 2127 | if (rword == skip_more_for_this_rword && flag_skip) { |
@@ -2145,7 +2145,7 @@ static int run_list(struct pipe *pi) | |||
2145 | break; /* "if <true> then ... ELIF cmd": skip cmd and all following ones */ | 2145 | break; /* "if <true> then ... ELIF cmd": skip cmd and all following ones */ |
2146 | #endif | 2146 | #endif |
2147 | #if ENABLE_HUSH_LOOPS | 2147 | #if ENABLE_HUSH_LOOPS |
2148 | if (rword == RES_FOR && pi->num_progs) { | 2148 | if (rword == RES_FOR && pi->num_progs) { /* hmm why "&& pi->num_progs"? */ |
2149 | if (!for_lcur) { | 2149 | if (!for_lcur) { |
2150 | /* first loop through for */ | 2150 | /* first loop through for */ |
2151 | 2151 | ||
@@ -2158,7 +2158,7 @@ static int run_list(struct pipe *pi) | |||
2158 | char **vals; | 2158 | char **vals; |
2159 | 2159 | ||
2160 | vals = (char**)encoded_dollar_at_argv; | 2160 | vals = (char**)encoded_dollar_at_argv; |
2161 | if (loop_top->next->res_word == RES_IN) { | 2161 | if (pi->next->res_word == RES_IN) { |
2162 | /* if no variable values after "in" we skip "for" */ | 2162 | /* if no variable values after "in" we skip "for" */ |
2163 | if (!pi->next->progs->argv) | 2163 | if (!pi->next->progs->argv) |
2164 | continue; | 2164 | continue; |
@@ -2196,8 +2196,8 @@ static int run_list(struct pipe *pi) | |||
2196 | if (rword == RES_DONE) { /* end of loop? */ | 2196 | if (rword == RES_DONE) { /* end of loop? */ |
2197 | if (flag_run_loop) { | 2197 | if (flag_run_loop) { |
2198 | flag_goto_looptop = 1; | 2198 | flag_goto_looptop = 1; |
2199 | } else { | 2199 | // } else { |
2200 | loop_top = NULL; | 2200 | // loop_top = NULL; |
2201 | } | 2201 | } |
2202 | continue; //TEST /* "done" has no cmd anyway */ | 2202 | continue; //TEST /* "done" has no cmd anyway */ |
2203 | } | 2203 | } |