bc: remove redundant JUMP generation when parsing 'while'
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 16 Dec 2018 22:02:22 +0000 (23:02 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 16 Dec 2018 22:02:22 +0000 (23:02 +0100)
function                                             old     new   delta
zbc_parse_stmt_possibly_auto                        2065    2025     -40
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-40)             Total: -40 bytes
   text    data     bss     dec     hex filename
 982035     485    7296  989816   f1a78 busybox_old
 981995     485    7296  989776   f1a50 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
miscutils/bc.c
testsuite/bc.tests

index 925950d78db5e0a668fdbf785c9b2eeb401d6f7a..af57b3d6c70e37c55c7bc7b33cbb63092272c835 100644 (file)
@@ -4175,7 +4175,7 @@ static BC_STATUS zbc_parse_while(BcParse *p)
        BcStatus s;
        BcInstPtr ip;
        size_t *label;
-       size_t n;
+       size_t cond_idx;
 
        s = zbc_lex_next(&p->l);
        if (s) RETURN_STATUS(s);
@@ -4183,10 +4183,10 @@ static BC_STATUS zbc_parse_while(BcParse *p)
        s = zbc_lex_next(&p->l);
        if (s) RETURN_STATUS(s);
 
-       ip.idx = p->func->labels.len;
+       cond_idx = p->func->labels.len;
 
        bc_vec_push(&p->func->labels, &p->func->code.len);
-       bc_vec_push(&p->conds, &ip.idx);
+       bc_vec_push(&p->conds, &cond_idx);
 
        ip.idx = p->func->labels.len;
        ip.func = 1;
@@ -4209,15 +4209,9 @@ static BC_STATUS zbc_parse_while(BcParse *p)
        s = zbc_parse_stmt_fail_if_bare_NLINE(p, false, "while");
        if (s) RETURN_STATUS(s);
 
-       n = *((size_t *) bc_vec_top(&p->conds));
-       bc_parse_push(p, BC_INST_JUMP);
-       bc_parse_pushIndex(p, n);
-
-       label = bc_vec_top(&p->conds);
-
-       dbg_lex("%s:%d BC_INST_JUMP to %d", __func__, __LINE__, *label);
+       dbg_lex("%s:%d BC_INST_JUMP to %d", __func__, __LINE__, cond_idx);
        bc_parse_push(p, BC_INST_JUMP);
-       bc_parse_pushIndex(p, *label);
+       bc_parse_pushIndex(p, cond_idx);
 
        label = bc_vec_item(&p->func->labels, ip.idx);
        dbg_lex("%s:%d rewriting label: %d -> %d", __func__, __LINE__, *label, p->func->code.len);
index 987461ebbc84ea6d82ed2b0baca1aa77c0bf2848..0690e9c6f209bc4973805578e57e977b2115edb5 100755 (executable)
@@ -107,6 +107,33 @@ if(1) {
 99
 "
 
+testing "bc continue in if" \
+       "bc" \
+       "\
+11
+21
+11
+31
+99
+" \
+       "" "\
+i=2
+while(i--) {
+        11
+        if(i) {
+                21
+                continue
+                22
+        } else {
+                31
+                continue
+                32
+       }
+        12
+}
+99
+"
+
 tar xJf bc_large.tar.xz
 
 for f in bc*.bc; do