From: Herbert Xu <herbert@gondor.apana.org.au>
To: dash@vger.kernel.org
Subject: [EVAL] Move common skipcount logic into skiploop
Date: Mon, 6 Oct 2014 21:23:56 +0800 [thread overview]
Message-ID: <20141006132355.GA22730@gondor.apana.org.au> (raw)
commit 598d300ffa0b9542a88feae900ccdd29e35374cf
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date: Mon Oct 6 20:45:04 2014 +0800
[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@gondor.apana.org.au>
diff --git a/ChangeLog b/ChangeLog
index b70fa88..1d88e13 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
* Exit without arguments in a trap should use status outside traps.
* Do not allow break to break across function calls.
+ * Move common skipcount logic into skiploop.
2014-10-03 Herbert Xu <herbert@gondor.apana.org.au>
diff --git a/src/eval.c b/src/eval.c
index eb5b120..daccf3d 100644
--- a/src/eval.c
+++ b/src/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);
}
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
reply other threads:[~2014-10-06 13:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141006132355.GA22730@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=dash@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).