klibc-bot for Herbert Xu
2019-Jan-25 03:15 UTC
[klibc] [klibc:update-dash] [EVAL] Move common skipcount logic into skiploop
Commit-ID: dde2b81c52d389b21abd0814dac5a4988be80725 Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=dde2b81c52d389b21abd0814dac5a4988be80725 Author: Herbert Xu <herbert at gondor.apana.org.au> AuthorDate: Mon, 6 Oct 2014 20:45:04 +0800 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Fri, 25 Jan 2019 02:57:21 +0000 [klibc] [EVAL] Move common skipcount logic into skiploop The functions evalloop and evalfor share the logic on checking and updating skipcount. This patch moves that into the helper function skiploop. Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au> Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/dash/eval.c | 56 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/usr/dash/eval.c b/usr/dash/eval.c index 204f1e57..bb106368 100644 --- a/usr/dash/eval.c +++ b/usr/dash/eval.c @@ -339,27 +339,45 @@ void evaltreenr(union node *n, int flags) #endif +static int skiploop(void) +{ + int skip = evalskip; + + switch (skip) { + case 0: + break; + + case SKIPBREAK: + case SKIPCONT: + if (likely(--skipcount <= 0)) { + evalskip = 0; + break; + } + + skip = SKIPBREAK; + break; + } + + return skip; +} + + STATIC void evalloop(union node *n, int flags) { + int skip; int status; loopnest++; status = 0; flags &= EV_TESTED; - for (;;) { + do { int i; evaltree(n->nbinary.ch1, EV_TESTED); - if (evalskip) { -skipping: if (evalskip == SKIPCONT && --skipcount <= 0) { - evalskip = 0; - continue; - } - if (evalskip == SKIPBREAK && --skipcount <= 0) - evalskip = 0; - break; - } + skip = skiploop(); + if (skip) + continue; i = exitstatus; if (n->type != NWHILE) i = !i; @@ -367,9 +385,8 @@ skipping: if (evalskip == SKIPCONT && --skipcount <= 0) { break; evaltree(n->nbinary.ch2, flags); status = exitstatus; - if (evalskip) - goto skipping; - } + skip = skiploop(); + } while (!(skip & ~SKIPCONT)); loopnest--; exitstatus = status; } @@ -392,9 +409,6 @@ evalfor(union node *n, int flags) arglist.lastp = &arglist.list; for (argp = n->nfor.args ; argp ; argp = argp->narg.next) { expandarg(argp, &arglist, EXP_FULL | EXP_TILDE); - /* XXX */ - if (evalskip) - goto out; } *arglist.lastp = NULL; @@ -404,18 +418,10 @@ evalfor(union node *n, int flags) for (sp = arglist.list ; sp ; sp = sp->next) { setvar(n->nfor.var, sp->text, 0); evaltree(n->nfor.body, flags); - if (evalskip) { - if (evalskip == SKIPCONT && --skipcount <= 0) { - evalskip = 0; - continue; - } - if (evalskip == SKIPBREAK && --skipcount <= 0) - evalskip = 0; + if (skiploop() & ~SKIPCONT) break; - } } loopnest--; -out: popstackmark(&smark); }
Seemingly Similar Threads
- [klibc:update-dash] dash: [EVAL] Move common skipcount logic into skiploop
- [klibc:update-dash] eval: Return status in eval functions
- [klibc:update-dash] dash: eval: Return status in eval functions
- [klibc:master] [BUILTIN] Merge SKIPFUNC/ SKIPFILE and only clear SKIPFUNC when leaving dotcmd
- [klibc:update-dash] [BUILTIN] Return without arguments in a trap should use status outside traps