diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-01-09 11:17:19 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-02-14 14:40:57 +0100 |
commit | b5709543631aaa9a198dbb726b1d302a1696410e (patch) | |
tree | effcd1e7f61be9193c3b40229aaa6044daffdd1f | |
parent | c28dc0b58bac65e3904828a82ea29712ba967e84 (diff) | |
download | busybox-w32-b5709543631aaa9a198dbb726b1d302a1696410e.tar.gz busybox-w32-b5709543631aaa9a198dbb726b1d302a1696410e.tar.bz2 busybox-w32-b5709543631aaa9a198dbb726b1d302a1696410e.zip |
bc: code shrink
function old new delta
xc_parse_pushInst_and_Index - 16 +16
zbc_parse_expr 1818 1816 -2
xc_parse_pushIndex 65 61 -4
zbc_parse_pushSTR 63 58 -5
zbc_parse_name 448 442 -6
xc_parse_pushNUM 74 67 -7
zdc_parse_expr 479 470 -9
bc_parse_pushJUMP_ZERO 21 12 -9
bc_parse_pushJUMP 21 12 -9
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/8 up/down: 16/-51) Total: -35 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index cef0637bf..8e0069658 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -3497,11 +3497,11 @@ static BC_STATUS zdc_lex_token(void) | |||
3497 | #define zdc_lex_token(...) (zdc_lex_token(__VA_ARGS__) COMMA_SUCCESS) | 3497 | #define zdc_lex_token(...) (zdc_lex_token(__VA_ARGS__) COMMA_SUCCESS) |
3498 | #endif // ENABLE_DC | 3498 | #endif // ENABLE_DC |
3499 | 3499 | ||
3500 | static void xc_parse_push(char i) | 3500 | static void xc_parse_push(unsigned i) |
3501 | { | 3501 | { |
3502 | BcVec *code = &G.prs.func->code; | 3502 | BcVec *code = &G.prs.func->code; |
3503 | dbg_compile("%s:%d pushing bytecode %zd:%d", __func__, __LINE__, code->len, i); | 3503 | dbg_compile("%s:%d pushing bytecode %zd:%d", __func__, __LINE__, code->len, i); |
3504 | bc_vec_pushByte(code, i); | 3504 | bc_vec_pushByte(code, (uint8_t)i); |
3505 | } | 3505 | } |
3506 | 3506 | ||
3507 | static void xc_parse_pushName(char *name) | 3507 | static void xc_parse_pushName(char *name) |
@@ -3556,17 +3556,21 @@ static void xc_parse_pushIndex(size_t idx) | |||
3556 | } while (idx != 0); | 3556 | } while (idx != 0); |
3557 | } | 3557 | } |
3558 | 3558 | ||
3559 | static void xc_parse_pushInst_and_Index(unsigned inst, size_t idx) | ||
3560 | { | ||
3561 | xc_parse_push(inst); | ||
3562 | xc_parse_pushIndex(idx); | ||
3563 | } | ||
3564 | |||
3559 | #if ENABLE_BC | 3565 | #if ENABLE_BC |
3560 | static void bc_parse_pushJUMP(size_t idx) | 3566 | static void bc_parse_pushJUMP(size_t idx) |
3561 | { | 3567 | { |
3562 | xc_parse_push(BC_INST_JUMP); | 3568 | xc_parse_pushInst_and_Index(BC_INST_JUMP, idx); |
3563 | xc_parse_pushIndex(idx); | ||
3564 | } | 3569 | } |
3565 | 3570 | ||
3566 | static void bc_parse_pushJUMP_ZERO(size_t idx) | 3571 | static void bc_parse_pushJUMP_ZERO(size_t idx) |
3567 | { | 3572 | { |
3568 | xc_parse_push(BC_INST_JUMP_ZERO); | 3573 | xc_parse_pushInst_and_Index(BC_INST_JUMP_ZERO, idx); |
3569 | xc_parse_pushIndex(idx); | ||
3570 | } | 3574 | } |
3571 | 3575 | ||
3572 | static BC_STATUS zbc_parse_pushSTR(void) | 3576 | static BC_STATUS zbc_parse_pushSTR(void) |
@@ -3574,8 +3578,7 @@ static BC_STATUS zbc_parse_pushSTR(void) | |||
3574 | BcParse *p = &G.prs; | 3578 | BcParse *p = &G.prs; |
3575 | char *str = xstrdup(p->lex_strnumbuf.v); | 3579 | char *str = xstrdup(p->lex_strnumbuf.v); |
3576 | 3580 | ||
3577 | xc_parse_push(XC_INST_STR); | 3581 | xc_parse_pushInst_and_Index(XC_INST_STR, p->func->strs.len); |
3578 | xc_parse_pushIndex(p->func->strs.len); | ||
3579 | bc_vec_push(&p->func->strs, &str); | 3582 | bc_vec_push(&p->func->strs, &str); |
3580 | 3583 | ||
3581 | RETURN_STATUS(zxc_lex_next()); | 3584 | RETURN_STATUS(zxc_lex_next()); |
@@ -3594,8 +3597,7 @@ static void xc_parse_pushNUM(void) | |||
3594 | #else // DC | 3597 | #else // DC |
3595 | size_t idx = bc_vec_push(&G.prog.consts, &num); | 3598 | size_t idx = bc_vec_push(&G.prog.consts, &num); |
3596 | #endif | 3599 | #endif |
3597 | xc_parse_push(XC_INST_NUM); | 3600 | xc_parse_pushInst_and_Index(XC_INST_NUM, idx); |
3598 | xc_parse_pushIndex(idx); | ||
3599 | } | 3601 | } |
3600 | 3602 | ||
3601 | static BC_STATUS zxc_parse_text_init(const char *text) | 3603 | static BC_STATUS zxc_parse_text_init(const char *text) |
@@ -3815,8 +3817,7 @@ static BC_STATUS zbc_parse_params(uint8_t flags) | |||
3815 | } | 3817 | } |
3816 | } | 3818 | } |
3817 | 3819 | ||
3818 | xc_parse_push(BC_INST_CALL); | 3820 | xc_parse_pushInst_and_Index(BC_INST_CALL, nparams); |
3819 | xc_parse_pushIndex(nparams); | ||
3820 | 3821 | ||
3821 | RETURN_STATUS(BC_STATUS_SUCCESS); | 3822 | RETURN_STATUS(BC_STATUS_SUCCESS); |
3822 | } | 3823 | } |
@@ -4934,8 +4935,7 @@ static void dc_parse_string(void) | |||
4934 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); | 4935 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); |
4935 | 4936 | ||
4936 | str = xstrdup(p->lex_strnumbuf.v); | 4937 | str = xstrdup(p->lex_strnumbuf.v); |
4937 | xc_parse_push(XC_INST_STR); | 4938 | xc_parse_pushInst_and_Index(XC_INST_STR, len); |
4938 | xc_parse_pushIndex(len); | ||
4939 | bc_vec_push(&G.prog.strs, &str); | 4939 | bc_vec_push(&G.prog.strs, &str); |
4940 | 4940 | ||
4941 | // Explanation needed here | 4941 | // Explanation needed here |