diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-19 17:09:01 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-19 17:09:01 +0100 |
commit | dfe1dd20318e79423634593725e2d0229fb19fd3 (patch) | |
tree | 34af0cfa5cd8159a784d577c606558622e8b631b | |
parent | 65e1046abf28a3b73e56e6b17ae936e7b2f314c3 (diff) | |
download | busybox-w32-dfe1dd20318e79423634593725e2d0229fb19fd3.tar.gz busybox-w32-dfe1dd20318e79423634593725e2d0229fb19fd3.tar.bz2 busybox-w32-dfe1dd20318e79423634593725e2d0229fb19fd3.zip |
bc: "unsigned_n > 0" is shorter code than "unsigned_n >= 1"
function old new delta
zbc_program_print 680 677 -3
zbc_program_exec 4089 4085 -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-7) Total: -7 bytes
text data bss dec hex filename
981404 485 7296 989185 f1801 busybox_old
981397 485 7296 989178 f17fa busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 8d2c2705b..d62a852d5 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -707,8 +707,6 @@ typedef struct BcProgram { | |||
707 | size_t nchars; | 707 | size_t nchars; |
708 | } BcProgram; | 708 | } BcProgram; |
709 | 709 | ||
710 | #define BC_PROG_STACK(s, n) ((s)->len >= ((size_t) n)) | ||
711 | |||
712 | #define BC_PROG_MAIN (0) | 710 | #define BC_PROG_MAIN (0) |
713 | #define BC_PROG_READ (1) | 711 | #define BC_PROG_READ (1) |
714 | #if ENABLE_DC | 712 | #if ENABLE_DC |
@@ -838,6 +836,9 @@ struct globals { | |||
838 | # define COMMA_SUCCESS ,BC_STATUS_SUCCESS | 836 | # define COMMA_SUCCESS ,BC_STATUS_SUCCESS |
839 | #endif | 837 | #endif |
840 | 838 | ||
839 | #define STACK_HAS_MORE_THAN(s, n) ((s)->len > ((size_t)(n))) | ||
840 | #define STACK_HAS_EQUAL_OR_MORE_THAN(s, n) ((s)->len >= ((size_t)(n))) | ||
841 | |||
841 | #define BC_NUM_NEG(n, neg) ((((ssize_t)(n)) ^ -((ssize_t)(neg))) + (neg)) | 842 | #define BC_NUM_NEG(n, neg) ((((ssize_t)(n)) ^ -((ssize_t)(neg))) + (neg)) |
842 | #define BC_NUM_ONE(n) ((n)->len == 1 && (n)->rdx == 0 && (n)->num[0] == 1) | 843 | #define BC_NUM_ONE(n) ((n)->len == 1 && (n)->rdx == 0 && (n)->num[0] == 1) |
843 | #define BC_NUM_INT(n) ((n)->len - (n)->rdx) | 844 | #define BC_NUM_INT(n) ((n)->len - (n)->rdx) |
@@ -5048,7 +5049,7 @@ static BC_STATUS zbc_program_binOpPrep(BcResult **l, BcNum **ln, | |||
5048 | bool hex; | 5049 | bool hex; |
5049 | BcResultType lt, rt; | 5050 | BcResultType lt, rt; |
5050 | 5051 | ||
5051 | if (!BC_PROG_STACK(&G.prog.results, 2)) | 5052 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 1)) |
5052 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 5053 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
5053 | 5054 | ||
5054 | *r = bc_vec_item_rev(&G.prog.results, 0); | 5055 | *r = bc_vec_item_rev(&G.prog.results, 0); |
@@ -5091,7 +5092,7 @@ static BC_STATUS zbc_program_prep(BcResult **r, BcNum **n) | |||
5091 | { | 5092 | { |
5092 | BcStatus s; | 5093 | BcStatus s; |
5093 | 5094 | ||
5094 | if (!BC_PROG_STACK(&G.prog.results, 1)) | 5095 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 0)) |
5095 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 5096 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
5096 | *r = bc_vec_top(&G.prog.results); | 5097 | *r = bc_vec_top(&G.prog.results); |
5097 | 5098 | ||
@@ -5479,7 +5480,7 @@ static BC_STATUS zbc_program_print(char inst, size_t idx) | |||
5479 | BcNum *num; | 5480 | BcNum *num; |
5480 | bool pop = inst != BC_INST_PRINT; | 5481 | bool pop = inst != BC_INST_PRINT; |
5481 | 5482 | ||
5482 | if (!BC_PROG_STACK(&G.prog.results, idx + 1)) | 5483 | if (!STACK_HAS_MORE_THAN(&G.prog.results, idx)) |
5483 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 5484 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
5484 | 5485 | ||
5485 | r = bc_vec_item_rev(&G.prog.results, idx); | 5486 | r = bc_vec_item_rev(&G.prog.results, idx); |
@@ -5595,7 +5596,7 @@ static BC_STATUS zbc_program_assignStr(BcResult *r, BcVec *v, bool push) | |||
5595 | res.t = BC_RESULT_STR; | 5596 | res.t = BC_RESULT_STR; |
5596 | 5597 | ||
5597 | if (!push) { | 5598 | if (!push) { |
5598 | if (!BC_PROG_STACK(&G.prog.results, 2)) | 5599 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 1)) |
5599 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 5600 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
5600 | bc_vec_pop(v); | 5601 | bc_vec_pop(v); |
5601 | bc_vec_pop(&G.prog.results); | 5602 | bc_vec_pop(&G.prog.results); |
@@ -5618,7 +5619,7 @@ static BC_STATUS zbc_program_copyToVar(char *name, bool var) | |||
5618 | BcVec *v; | 5619 | BcVec *v; |
5619 | BcNum *n; | 5620 | BcNum *n; |
5620 | 5621 | ||
5621 | if (!BC_PROG_STACK(&G.prog.results, 1)) | 5622 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 0)) |
5622 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 5623 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
5623 | 5624 | ||
5624 | ptr = bc_vec_top(&G.prog.results); | 5625 | ptr = bc_vec_top(&G.prog.results); |
@@ -5761,7 +5762,7 @@ static BC_STATUS bc_program_pushVar(char *code, size_t *bgn, | |||
5761 | BcNum *num = bc_vec_top(v); | 5762 | BcNum *num = bc_vec_top(v); |
5762 | 5763 | ||
5763 | free(name); | 5764 | free(name); |
5764 | if (!BC_PROG_STACK(v, 2 - copy)) { | 5765 | if (!STACK_HAS_MORE_THAN(v, 1 - copy)) { |
5765 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 5766 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
5766 | } | 5767 | } |
5767 | 5768 | ||
@@ -5916,7 +5917,7 @@ static BC_STATUS zbc_program_return(char inst) | |||
5916 | size_t i; | 5917 | size_t i; |
5917 | BcInstPtr *ip = bc_vec_top(&G.prog.exestack); | 5918 | BcInstPtr *ip = bc_vec_top(&G.prog.exestack); |
5918 | 5919 | ||
5919 | if (!BC_PROG_STACK(&G.prog.results, ip->len + inst == BC_INST_RET)) | 5920 | if (!STACK_HAS_EQUAL_OR_MORE_THAN(&G.prog.results, ip->len + (inst == BC_INST_RET))) |
5920 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 5921 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
5921 | 5922 | ||
5922 | f = bc_program_func(ip->func); | 5923 | f = bc_program_func(ip->func); |
@@ -5980,7 +5981,7 @@ static BC_STATUS zbc_program_builtin(char inst) | |||
5980 | BcResult res; | 5981 | BcResult res; |
5981 | bool len = inst == BC_INST_LENGTH; | 5982 | bool len = inst == BC_INST_LENGTH; |
5982 | 5983 | ||
5983 | if (!BC_PROG_STACK(&G.prog.results, 1)) | 5984 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 0)) |
5984 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 5985 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
5985 | opnd = bc_vec_top(&G.prog.results); | 5986 | opnd = bc_vec_top(&G.prog.results); |
5986 | 5987 | ||
@@ -6054,7 +6055,7 @@ static BC_STATUS zbc_program_modexp(void) | |||
6054 | BcResult *r1, *r2, *r3, res; | 6055 | BcResult *r1, *r2, *r3, res; |
6055 | BcNum *n1, *n2, *n3; | 6056 | BcNum *n1, *n2, *n3; |
6056 | 6057 | ||
6057 | if (!BC_PROG_STACK(&G.prog.results, 3)) | 6058 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 2)) |
6058 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 6059 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
6059 | s = zbc_program_binOpPrep(&r2, &n2, &r3, &n3, false); | 6060 | s = zbc_program_binOpPrep(&r2, &n2, &r3, &n3, false); |
6060 | if (s) RETURN_STATUS(s); | 6061 | if (s) RETURN_STATUS(s); |
@@ -6112,7 +6113,7 @@ static BC_STATUS zbc_program_asciify(void) | |||
6112 | size_t len = G.prog.strs.len, idx; | 6113 | size_t len = G.prog.strs.len, idx; |
6113 | unsigned long val; | 6114 | unsigned long val; |
6114 | 6115 | ||
6115 | if (!BC_PROG_STACK(&G.prog.results, 1)) | 6116 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 0)) |
6116 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 6117 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
6117 | r = bc_vec_top(&G.prog.results); | 6118 | r = bc_vec_top(&G.prog.results); |
6118 | 6119 | ||
@@ -6184,7 +6185,7 @@ static BC_STATUS zbc_program_printStream(void) | |||
6184 | size_t idx; | 6185 | size_t idx; |
6185 | char *str; | 6186 | char *str; |
6186 | 6187 | ||
6187 | if (!BC_PROG_STACK(&G.prog.results, 1)) | 6188 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 0)) |
6188 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 6189 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
6189 | r = bc_vec_top(&G.prog.results); | 6190 | r = bc_vec_top(&G.prog.results); |
6190 | 6191 | ||
@@ -6239,7 +6240,7 @@ static BC_STATUS zbc_program_execStr(char *code, size_t *bgn, bool cond) | |||
6239 | BcInstPtr ip; | 6240 | BcInstPtr ip; |
6240 | size_t fidx, sidx; | 6241 | size_t fidx, sidx; |
6241 | 6242 | ||
6242 | if (!BC_PROG_STACK(&G.prog.results, 1)) | 6243 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 0)) |
6243 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 6244 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
6244 | 6245 | ||
6245 | r = bc_vec_top(&G.prog.results); | 6246 | r = bc_vec_top(&G.prog.results); |
@@ -6452,7 +6453,7 @@ static BC_STATUS zbc_program_exec(void) | |||
6452 | break; | 6453 | break; |
6453 | case BC_INST_POP: | 6454 | case BC_INST_POP: |
6454 | dbg_exec("BC_INST_POP:"); | 6455 | dbg_exec("BC_INST_POP:"); |
6455 | if (!BC_PROG_STACK(&G.prog.results, 1)) | 6456 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 0)) |
6456 | s = bc_error_stack_has_too_few_elements(); | 6457 | s = bc_error_stack_has_too_few_elements(); |
6457 | else | 6458 | else |
6458 | bc_vec_pop(&G.prog.results); | 6459 | bc_vec_pop(&G.prog.results); |
@@ -6534,7 +6535,7 @@ static BC_STATUS zbc_program_exec(void) | |||
6534 | bc_program_stackLen(); | 6535 | bc_program_stackLen(); |
6535 | break; | 6536 | break; |
6536 | case BC_INST_DUPLICATE: | 6537 | case BC_INST_DUPLICATE: |
6537 | if (!BC_PROG_STACK(&G.prog.results, 1)) | 6538 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 0)) |
6538 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 6539 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
6539 | ptr = bc_vec_top(&G.prog.results); | 6540 | ptr = bc_vec_top(&G.prog.results); |
6540 | bc_result_copy(&r, ptr); | 6541 | bc_result_copy(&r, ptr); |
@@ -6542,7 +6543,7 @@ static BC_STATUS zbc_program_exec(void) | |||
6542 | break; | 6543 | break; |
6543 | case BC_INST_SWAP: { | 6544 | case BC_INST_SWAP: { |
6544 | BcResult *ptr2; | 6545 | BcResult *ptr2; |
6545 | if (!BC_PROG_STACK(&G.prog.results, 2)) | 6546 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 1)) |
6546 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 6547 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
6547 | ptr = bc_vec_item_rev(&G.prog.results, 0); | 6548 | ptr = bc_vec_item_rev(&G.prog.results, 0); |
6548 | ptr2 = bc_vec_item_rev(&G.prog.results, 1); | 6549 | ptr2 = bc_vec_item_rev(&G.prog.results, 1); |
@@ -6570,7 +6571,7 @@ static BC_STATUS zbc_program_exec(void) | |||
6570 | break; | 6571 | break; |
6571 | } | 6572 | } |
6572 | case BC_INST_QUIT: | 6573 | case BC_INST_QUIT: |
6573 | dbg_exec("BC_INST_NEG:"); | 6574 | dbg_exec("BC_INST_QUIT:"); |
6574 | if (G.prog.exestack.len <= 2) | 6575 | if (G.prog.exestack.len <= 2) |
6575 | QUIT_OR_RETURN_TO_MAIN; | 6576 | QUIT_OR_RETURN_TO_MAIN; |
6576 | bc_vec_npop(&G.prog.exestack, 2); | 6577 | bc_vec_npop(&G.prog.exestack, 2); |