diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-10 20:17:24 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-10 20:17:24 +0100 |
| commit | fa35e598ab3d98037d0db05b257f787ecb4b7a74 (patch) | |
| tree | a3f9dbbe6d3454ebd3c910428829a4d7d92c163d | |
| parent | 86e63cdeca93afae43c7d59a863bedccc3ea0c55 (diff) | |
| download | busybox-w32-fa35e598ab3d98037d0db05b257f787ecb4b7a74.tar.gz busybox-w32-fa35e598ab3d98037d0db05b257f787ecb4b7a74.tar.bz2 busybox-w32-fa35e598ab3d98037d0db05b257f787ecb4b7a74.zip | |
bc: optimize non-interactive config: we know that many functions always succeed
function old new delta
bc_program_assign 475 471 -4
bc_program_prep 87 81 -6
bc_parse_parse 423 417 -6
bc_num_p 440 434 -6
bc_program_printStream 153 143 -10
bc_program_execStr 478 468 -10
bc_parse_auto 275 265 -10
bc_num_k 925 913 -12
bc_program_copyToVar 307 289 -18
bc_program_binOpPrep 289 271 -18
bc_num_printNum 489 471 -18
bc_num_m 287 269 -18
bc_program_pushArray 139 113 -26
bc_program_modexp 707 677 -30
bc_program_print 704 667 -37
bc_program_exec 4010 3920 -90
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/16 up/down: 0/-319) Total: -319 bytes
text data bss dec hex filename
983202 485 7296 990983 f1f07 busybox_old
982883 485 7296 990664 f1dc8 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | miscutils/bc.c | 73 |
1 files changed, 60 insertions, 13 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index aa478e461..3b9b4d54e 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
| @@ -977,15 +977,18 @@ static void bc_verror_msg(const char *fmt, va_list p) | |||
| 977 | } | 977 | } |
| 978 | 978 | ||
| 979 | #if ENABLE_FEATURE_BC_SIGNALS | 979 | #if ENABLE_FEATURE_BC_SIGNALS |
| 980 | # define ERRORFUNC /*nothing*/ | 980 | # define ERRORFUNC /*nothing*/ |
| 981 | # define ERROR_RETURN(a) a | 981 | # define ERROR_RETURN(a) a |
| 982 | # define ERRORS_ARE_FATAL 0 | ||
| 982 | #else | 983 | #else |
| 983 | # if ENABLE_FEATURE_CLEAN_UP | 984 | # if ENABLE_FEATURE_CLEAN_UP |
| 984 | # define ERRORFUNC /*nothing*/ | 985 | # define ERRORFUNC /*nothing*/ |
| 985 | # define ERROR_RETURN(a) a | 986 | # define ERROR_RETURN(a) a |
| 987 | # define ERRORS_ARE_FATAL 0 | ||
| 986 | # else | 988 | # else |
| 987 | # define ERRORFUNC NORETURN | 989 | # define ERRORFUNC NORETURN |
| 988 | # define ERROR_RETURN(a) /*nothing*/ | 990 | # define ERROR_RETURN(a) /*nothing*/ |
| 991 | # define ERRORS_ARE_FATAL 1 | ||
| 989 | # endif | 992 | # endif |
| 990 | #endif | 993 | #endif |
| 991 | 994 | ||
| @@ -1476,6 +1479,9 @@ static BcStatus bc_num_ulong(BcNum *n, unsigned long *result_p) | |||
| 1476 | 1479 | ||
| 1477 | return BC_STATUS_SUCCESS; | 1480 | return BC_STATUS_SUCCESS; |
| 1478 | } | 1481 | } |
| 1482 | #if ERRORS_ARE_FATAL | ||
| 1483 | # define bc_num_ulong(...) (bc_num_ulong(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
| 1484 | #endif | ||
| 1479 | 1485 | ||
| 1480 | static void bc_num_ulong2num(BcNum *n, unsigned long val) | 1486 | static void bc_num_ulong2num(BcNum *n, unsigned long val) |
| 1481 | { | 1487 | { |
| @@ -1673,6 +1679,9 @@ static BcStatus bc_num_shift(BcNum *n, size_t places) | |||
| 1673 | 1679 | ||
| 1674 | return BC_STATUS_SUCCESS; | 1680 | return BC_STATUS_SUCCESS; |
| 1675 | } | 1681 | } |
| 1682 | #if ERRORS_ARE_FATAL | ||
| 1683 | # define bc_num_shift(...) (bc_num_shift(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
| 1684 | #endif | ||
| 1676 | 1685 | ||
| 1677 | static BcStatus bc_num_inv(BcNum *a, BcNum *b, size_t scale) | 1686 | static BcStatus bc_num_inv(BcNum *a, BcNum *b, size_t scale) |
| 1678 | { | 1687 | { |
| @@ -2342,6 +2351,9 @@ err: | |||
| 2342 | bc_vec_free(&stack); | 2351 | bc_vec_free(&stack); |
| 2343 | return s; | 2352 | return s; |
| 2344 | } | 2353 | } |
| 2354 | #if ERRORS_ARE_FATAL | ||
| 2355 | # define bc_num_printNum(...) (bc_num_printNum(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
| 2356 | #endif | ||
| 2345 | 2357 | ||
| 2346 | static BcStatus bc_num_printBase(BcNum *n) | 2358 | static BcStatus bc_num_printBase(BcNum *n) |
| 2347 | { | 2359 | { |
| @@ -2372,6 +2384,9 @@ static BcStatus bc_num_printBase(BcNum *n) | |||
| 2372 | 2384 | ||
| 2373 | return s; | 2385 | return s; |
| 2374 | } | 2386 | } |
| 2387 | #if ERRORS_ARE_FATAL | ||
| 2388 | # define bc_num_printBase(...) (bc_num_printBase(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
| 2389 | #endif | ||
| 2375 | 2390 | ||
| 2376 | #if ENABLE_DC | 2391 | #if ENABLE_DC |
| 2377 | static BcStatus bc_num_stream(BcNum *n, BcNum *base) | 2392 | static BcStatus bc_num_stream(BcNum *n, BcNum *base) |
| @@ -2526,6 +2541,9 @@ static BcStatus bc_num_parse(BcNum *n, const char *val, BcNum *base, | |||
| 2526 | 2541 | ||
| 2527 | return BC_STATUS_SUCCESS; | 2542 | return BC_STATUS_SUCCESS; |
| 2528 | } | 2543 | } |
| 2544 | #if ERRORS_ARE_FATAL | ||
| 2545 | # define bc_num_parse(...) (bc_num_parse(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
| 2546 | #endif | ||
| 2529 | 2547 | ||
| 2530 | static BcStatus bc_num_print(BcNum *n, bool newline) | 2548 | static BcStatus bc_num_print(BcNum *n, bool newline) |
| 2531 | { | 2549 | { |
| @@ -2549,6 +2567,9 @@ static BcStatus bc_num_print(BcNum *n, bool newline) | |||
| 2549 | 2567 | ||
| 2550 | return s; | 2568 | return s; |
| 2551 | } | 2569 | } |
| 2570 | #if ERRORS_ARE_FATAL | ||
| 2571 | # define bc_num_print(...) (bc_num_print(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
| 2572 | #endif | ||
| 2552 | 2573 | ||
| 2553 | static FAST_FUNC BcStatus bc_num_add(BcNum *a, BcNum *b, BcNum *c, size_t scale) | 2574 | static FAST_FUNC BcStatus bc_num_add(BcNum *a, BcNum *b, BcNum *c, size_t scale) |
| 2554 | { | 2575 | { |
| @@ -2787,6 +2808,9 @@ static BcStatus bc_func_insert(BcFunc *f, char *name, bool var) | |||
| 2787 | 2808 | ||
| 2788 | return BC_STATUS_SUCCESS; | 2809 | return BC_STATUS_SUCCESS; |
| 2789 | } | 2810 | } |
| 2811 | #if ERRORS_ARE_FATAL | ||
| 2812 | # define bc_func_insert(...) (bc_func_insert(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
| 2813 | #endif | ||
| 2790 | #endif | 2814 | #endif |
| 2791 | 2815 | ||
| 2792 | static void bc_func_init(BcFunc *f) | 2816 | static void bc_func_init(BcFunc *f) |
| @@ -2992,6 +3016,9 @@ static BcStatus bc_lex_number(BcLex *l, char start) | |||
| 2992 | 3016 | ||
| 2993 | return BC_STATUS_SUCCESS; | 3017 | return BC_STATUS_SUCCESS; |
| 2994 | } | 3018 | } |
| 3019 | #if ERRORS_ARE_FATAL | ||
| 3020 | # define bc_lex_number(...) (bc_lex_number(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
| 3021 | #endif | ||
| 2995 | 3022 | ||
| 2996 | static BcStatus bc_lex_name(BcLex *l) | 3023 | static BcStatus bc_lex_name(BcLex *l) |
| 2997 | { | 3024 | { |
| @@ -5410,8 +5437,6 @@ static BcVec* bc_program_search(char *id, bool var) | |||
| 5410 | 5437 | ||
| 5411 | static BcStatus bc_program_num(BcResult *r, BcNum **num, bool hex) | 5438 | static BcStatus bc_program_num(BcResult *r, BcNum **num, bool hex) |
| 5412 | { | 5439 | { |
| 5413 | BcStatus s = BC_STATUS_SUCCESS; | ||
| 5414 | |||
| 5415 | switch (r->t) { | 5440 | switch (r->t) { |
| 5416 | 5441 | ||
| 5417 | case BC_RESULT_STR: | 5442 | case BC_RESULT_STR: |
| @@ -5426,6 +5451,7 @@ static BcStatus bc_program_num(BcResult *r, BcNum **num, bool hex) | |||
| 5426 | 5451 | ||
| 5427 | case BC_RESULT_CONSTANT: | 5452 | case BC_RESULT_CONSTANT: |
| 5428 | { | 5453 | { |
| 5454 | BcStatus s; | ||
| 5429 | char **str = bc_vec_item(&G.prog.consts, r->d.id.idx); | 5455 | char **str = bc_vec_item(&G.prog.consts, r->d.id.idx); |
| 5430 | size_t base_t, len = strlen(*str); | 5456 | size_t base_t, len = strlen(*str); |
| 5431 | BcNum *base; | 5457 | BcNum *base; |
| @@ -5480,8 +5506,11 @@ static BcStatus bc_program_num(BcResult *r, BcNum **num, bool hex) | |||
| 5480 | } | 5506 | } |
| 5481 | } | 5507 | } |
| 5482 | 5508 | ||
| 5483 | return s; | 5509 | return BC_STATUS_SUCCESS; |
| 5484 | } | 5510 | } |
| 5511 | #if ERRORS_ARE_FATAL | ||
| 5512 | # define bc_program_num(...) (bc_program_num(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
| 5513 | #endif | ||
| 5485 | 5514 | ||
| 5486 | static BcStatus bc_program_binOpPrep(BcResult **l, BcNum **ln, | 5515 | static BcStatus bc_program_binOpPrep(BcResult **l, BcNum **ln, |
| 5487 | BcResult **r, BcNum **rn, bool assign) | 5516 | BcResult **r, BcNum **rn, bool assign) |
| @@ -5544,6 +5573,9 @@ static BcStatus bc_program_prep(BcResult **r, BcNum **n) | |||
| 5544 | 5573 | ||
| 5545 | return s; | 5574 | return s; |
| 5546 | } | 5575 | } |
| 5576 | #if ERRORS_ARE_FATAL | ||
| 5577 | # define bc_program_prep(...) (bc_program_prep(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
| 5578 | #endif | ||
| 5547 | 5579 | ||
| 5548 | static void bc_program_retire(BcResult *r, BcResultType t) | 5580 | static void bc_program_retire(BcResult *r, BcResultType t) |
| 5549 | { | 5581 | { |
| @@ -5744,7 +5776,7 @@ static void bc_program_printString(const char *str) | |||
| 5744 | 5776 | ||
| 5745 | static BcStatus bc_program_print(char inst, size_t idx) | 5777 | static BcStatus bc_program_print(char inst, size_t idx) |
| 5746 | { | 5778 | { |
| 5747 | BcStatus s = BC_STATUS_SUCCESS; | 5779 | BcStatus s; |
| 5748 | BcResult *r; | 5780 | BcResult *r; |
| 5749 | BcNum *num; | 5781 | BcNum *num; |
| 5750 | bool pop = inst != BC_INST_PRINT; | 5782 | bool pop = inst != BC_INST_PRINT; |
| @@ -5786,6 +5818,9 @@ static BcStatus bc_program_print(char inst, size_t idx) | |||
| 5786 | 5818 | ||
| 5787 | return s; | 5819 | return s; |
| 5788 | } | 5820 | } |
| 5821 | #if ERRORS_ARE_FATAL | ||
| 5822 | # define bc_program_print(...) (bc_program_print(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
| 5823 | #endif | ||
| 5789 | 5824 | ||
| 5790 | static BcStatus bc_program_negate(void) | 5825 | static BcStatus bc_program_negate(void) |
| 5791 | { | 5826 | { |
| @@ -5804,6 +5839,9 @@ static BcStatus bc_program_negate(void) | |||
| 5804 | 5839 | ||
| 5805 | return s; | 5840 | return s; |
| 5806 | } | 5841 | } |
| 5842 | #if ERRORS_ARE_FATAL | ||
| 5843 | # define bc_program_negate(...) (bc_program_negate(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
| 5844 | #endif | ||
| 5807 | 5845 | ||
| 5808 | static BcStatus bc_program_logical(char inst) | 5846 | static BcStatus bc_program_logical(char inst) |
| 5809 | { | 5847 | { |
| @@ -6120,6 +6158,9 @@ err: | |||
| 6120 | if (s) free(r.d.id.name); | 6158 | if (s) free(r.d.id.name); |
| 6121 | return s; | 6159 | return s; |
| 6122 | } | 6160 | } |
| 6161 | #if ERRORS_ARE_FATAL | ||
| 6162 | # define bc_program_pushArray(...) (bc_program_pushArray(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
| 6163 | #endif | ||
| 6123 | 6164 | ||
| 6124 | #if ENABLE_BC | 6165 | #if ENABLE_BC |
| 6125 | static BcStatus bc_program_incdec(char inst) | 6166 | static BcStatus bc_program_incdec(char inst) |
| @@ -6153,6 +6194,9 @@ static BcStatus bc_program_incdec(char inst) | |||
| 6153 | 6194 | ||
| 6154 | return s; | 6195 | return s; |
| 6155 | } | 6196 | } |
| 6197 | #if ERRORS_ARE_FATAL | ||
| 6198 | # define bc_program_incdec(...) (bc_program_incdec(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
| 6199 | #endif | ||
| 6156 | 6200 | ||
| 6157 | static BcStatus bc_program_call(char *code, size_t *idx) | 6201 | static BcStatus bc_program_call(char *code, size_t *idx) |
| 6158 | { | 6202 | { |
| @@ -6444,9 +6488,9 @@ static BcStatus bc_program_asciify(void) | |||
| 6444 | c = str2[0]; | 6488 | c = str2[0]; |
| 6445 | } | 6489 | } |
| 6446 | 6490 | ||
| 6447 | str = xmalloc(2); | 6491 | str = xzalloc(2); |
| 6448 | str[0] = c; | 6492 | str[0] = c; |
| 6449 | str[1] = '\0'; | 6493 | //str[1] = '\0'; - already is |
| 6450 | 6494 | ||
| 6451 | str2 = xstrdup(str); | 6495 | str2 = xstrdup(str); |
| 6452 | bc_program_addFunc(str2, &idx); | 6496 | bc_program_addFunc(str2, &idx); |
| @@ -6527,6 +6571,9 @@ static BcStatus bc_program_nquit(void) | |||
| 6527 | 6571 | ||
| 6528 | return s; | 6572 | return s; |
| 6529 | } | 6573 | } |
| 6574 | #if ERRORS_ARE_FATAL | ||
| 6575 | # define bc_program_nquit(...) (bc_program_nquit(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
| 6576 | #endif | ||
| 6530 | 6577 | ||
| 6531 | static BcStatus bc_program_execStr(char *code, size_t *bgn, | 6578 | static BcStatus bc_program_execStr(char *code, size_t *bgn, |
| 6532 | bool cond) | 6579 | bool cond) |
| @@ -6689,7 +6736,7 @@ static BcStatus bc_program_exec(void) | |||
| 6689 | bool cond = false; | 6736 | bool cond = false; |
| 6690 | 6737 | ||
| 6691 | while (ip->idx < func->code.len) { | 6738 | while (ip->idx < func->code.len) { |
| 6692 | BcStatus s; | 6739 | BcStatus s = BC_STATUS_SUCCESS; |
| 6693 | char inst = code[(ip->idx)++]; | 6740 | char inst = code[(ip->idx)++]; |
| 6694 | 6741 | ||
| 6695 | switch (inst) { | 6742 | switch (inst) { |
