mirror of
https://github.com/sheumann/hush.git
synced 2024-12-28 07:30:23 +00:00
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
This commit is contained in:
parent
12acec5ad4
commit
cf22c89f9a
30
shell/hush.c
30
shell/hush.c
@ -2016,7 +2016,7 @@ static int run_list(struct pipe *pi)
|
|||||||
char *case_word = NULL;
|
char *case_word = NULL;
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_HUSH_LOOPS
|
#if ENABLE_HUSH_LOOPS
|
||||||
struct pipe *loop_top;
|
struct pipe *loop_top = loop_top; /* just for compiler */
|
||||||
char *for_varname = NULL;
|
char *for_varname = NULL;
|
||||||
char **for_lcur = NULL;
|
char **for_lcur = NULL;
|
||||||
char **for_list = NULL;
|
char **for_list = NULL;
|
||||||
@ -2024,7 +2024,7 @@ static int run_list(struct pipe *pi)
|
|||||||
smallint flag_goto_looptop = 0;
|
smallint flag_goto_looptop = 0;
|
||||||
#endif
|
#endif
|
||||||
smallint flag_skip = 1;
|
smallint flag_skip = 1;
|
||||||
smalluint rcode = 0; /* probably for gcc only */
|
smalluint rcode = 0; /* probably just for compiler */
|
||||||
#if ENABLE_HUSH_IF
|
#if ENABLE_HUSH_IF
|
||||||
smalluint cond_code = 0;
|
smalluint cond_code = 0;
|
||||||
///experimentally off: last_cond_code seems to be bogus
|
///experimentally off: last_cond_code seems to be bogus
|
||||||
@ -2039,21 +2039,21 @@ static int run_list(struct pipe *pi)
|
|||||||
|
|
||||||
#if ENABLE_HUSH_LOOPS
|
#if ENABLE_HUSH_LOOPS
|
||||||
/* check syntax for "for" */
|
/* check syntax for "for" */
|
||||||
for (loop_top = pi; loop_top; loop_top = loop_top->next) {
|
for (struct pipe *cpipe = pi; cpipe; cpipe = cpipe->next) {
|
||||||
if (loop_top->res_word != RES_FOR && loop_top->res_word != RES_IN)
|
if (cpipe->res_word != RES_FOR && cpipe->res_word != RES_IN)
|
||||||
continue;
|
continue;
|
||||||
/* current word is FOR or IN (BOLD in comments below) */
|
/* current word is FOR or IN (BOLD in comments below) */
|
||||||
if (loop_top->next == NULL) {
|
if (cpipe->next == NULL) {
|
||||||
syntax("malformed for");
|
syntax("malformed for");
|
||||||
debug_printf_exec("run_list lvl %d return 1\n", run_list_level);
|
debug_printf_exec("run_list lvl %d return 1\n", run_list_level);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* "FOR v; do ..." and "for v IN a b; do..." are ok */
|
/* "FOR v; do ..." and "for v IN a b; do..." are ok */
|
||||||
if (loop_top->next->res_word == RES_DO)
|
if (cpipe->next->res_word == RES_DO)
|
||||||
continue;
|
continue;
|
||||||
/* next word is not "do". It must be "in" then ("FOR v in ...") */
|
/* next word is not "do". It must be "in" then ("FOR v in ...") */
|
||||||
if (loop_top->res_word == RES_IN /* "for v IN a b; not_do..."? */
|
if (cpipe->res_word == RES_IN /* "for v IN a b; not_do..."? */
|
||||||
|| loop_top->next->res_word != RES_IN /* FOR v not_do_and_not_in..."? */
|
|| cpipe->next->res_word != RES_IN /* FOR v not_do_and_not_in..."? */
|
||||||
) {
|
) {
|
||||||
syntax("malformed for");
|
syntax("malformed for");
|
||||||
debug_printf_exec("run_list lvl %d return 1\n", run_list_level);
|
debug_printf_exec("run_list lvl %d return 1\n", run_list_level);
|
||||||
@ -2118,10 +2118,10 @@ static int run_list(struct pipe *pi)
|
|||||||
if (rword == RES_WHILE || rword == RES_UNTIL || rword == RES_FOR) {
|
if (rword == RES_WHILE || rword == RES_UNTIL || rword == RES_FOR) {
|
||||||
/* start of a loop: remember it */
|
/* start of a loop: remember it */
|
||||||
flag_goto_looptop = 0; /* not yet reached final "done" */
|
flag_goto_looptop = 0; /* not yet reached final "done" */
|
||||||
if (!loop_top) { /* hmm why this check is needed? */
|
// if (!loop_top) { /* hmm why this check is needed? */
|
||||||
flag_run_loop = 0; /* suppose loop condition is false (for now) */
|
// flag_run_loop = 0; /* suppose loop condition is false (for now) */
|
||||||
loop_top = pi; /* remember where loop starts */
|
loop_top = pi; /* remember where loop starts */
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (rword == skip_more_for_this_rword && flag_skip) {
|
if (rword == skip_more_for_this_rword && flag_skip) {
|
||||||
@ -2145,7 +2145,7 @@ static int run_list(struct pipe *pi)
|
|||||||
break; /* "if <true> then ... ELIF cmd": skip cmd and all following ones */
|
break; /* "if <true> then ... ELIF cmd": skip cmd and all following ones */
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_HUSH_LOOPS
|
#if ENABLE_HUSH_LOOPS
|
||||||
if (rword == RES_FOR && pi->num_progs) {
|
if (rword == RES_FOR && pi->num_progs) { /* hmm why "&& pi->num_progs"? */
|
||||||
if (!for_lcur) {
|
if (!for_lcur) {
|
||||||
/* first loop through for */
|
/* first loop through for */
|
||||||
|
|
||||||
@ -2158,7 +2158,7 @@ static int run_list(struct pipe *pi)
|
|||||||
char **vals;
|
char **vals;
|
||||||
|
|
||||||
vals = (char**)encoded_dollar_at_argv;
|
vals = (char**)encoded_dollar_at_argv;
|
||||||
if (loop_top->next->res_word == RES_IN) {
|
if (pi->next->res_word == RES_IN) {
|
||||||
/* if no variable values after "in" we skip "for" */
|
/* if no variable values after "in" we skip "for" */
|
||||||
if (!pi->next->progs->argv)
|
if (!pi->next->progs->argv)
|
||||||
continue;
|
continue;
|
||||||
@ -2196,8 +2196,8 @@ static int run_list(struct pipe *pi)
|
|||||||
if (rword == RES_DONE) { /* end of loop? */
|
if (rword == RES_DONE) { /* end of loop? */
|
||||||
if (flag_run_loop) {
|
if (flag_run_loop) {
|
||||||
flag_goto_looptop = 1;
|
flag_goto_looptop = 1;
|
||||||
} else {
|
// } else {
|
||||||
loop_top = NULL;
|
// loop_top = NULL;
|
||||||
}
|
}
|
||||||
continue; //TEST /* "done" has no cmd anyway */
|
continue; //TEST /* "done" has no cmd anyway */
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user