From: Denys Vlasenko Date: Mon, 10 Dec 2018 19:17:24 +0000 (+0100) Subject: bc: optimize non-interactive config: we know that many functions always succeed X-Git-Tag: 1_30_0~225 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=fa35e598ab3d98037d0db05b257f787ecb4b7a74;p=oweals%2Fbusybox.git 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 --- 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) } #if ENABLE_FEATURE_BC_SIGNALS -# define ERRORFUNC /*nothing*/ -# define ERROR_RETURN(a) a +# define ERRORFUNC /*nothing*/ +# define ERROR_RETURN(a) a +# define ERRORS_ARE_FATAL 0 #else # if ENABLE_FEATURE_CLEAN_UP -# define ERRORFUNC /*nothing*/ -# define ERROR_RETURN(a) a +# define ERRORFUNC /*nothing*/ +# define ERROR_RETURN(a) a +# define ERRORS_ARE_FATAL 0 # else -# define ERRORFUNC NORETURN -# define ERROR_RETURN(a) /*nothing*/ +# define ERRORFUNC NORETURN +# define ERROR_RETURN(a) /*nothing*/ +# define ERRORS_ARE_FATAL 1 # endif #endif @@ -1476,6 +1479,9 @@ static BcStatus bc_num_ulong(BcNum *n, unsigned long *result_p) return BC_STATUS_SUCCESS; } +#if ERRORS_ARE_FATAL +# define bc_num_ulong(...) (bc_num_ulong(__VA_ARGS__), BC_STATUS_SUCCESS) +#endif static void bc_num_ulong2num(BcNum *n, unsigned long val) { @@ -1673,6 +1679,9 @@ static BcStatus bc_num_shift(BcNum *n, size_t places) return BC_STATUS_SUCCESS; } +#if ERRORS_ARE_FATAL +# define bc_num_shift(...) (bc_num_shift(__VA_ARGS__), BC_STATUS_SUCCESS) +#endif static BcStatus bc_num_inv(BcNum *a, BcNum *b, size_t scale) { @@ -2342,6 +2351,9 @@ err: bc_vec_free(&stack); return s; } +#if ERRORS_ARE_FATAL +# define bc_num_printNum(...) (bc_num_printNum(__VA_ARGS__), BC_STATUS_SUCCESS) +#endif static BcStatus bc_num_printBase(BcNum *n) { @@ -2372,6 +2384,9 @@ static BcStatus bc_num_printBase(BcNum *n) return s; } +#if ERRORS_ARE_FATAL +# define bc_num_printBase(...) (bc_num_printBase(__VA_ARGS__), BC_STATUS_SUCCESS) +#endif #if ENABLE_DC 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, return BC_STATUS_SUCCESS; } +#if ERRORS_ARE_FATAL +# define bc_num_parse(...) (bc_num_parse(__VA_ARGS__), BC_STATUS_SUCCESS) +#endif static BcStatus bc_num_print(BcNum *n, bool newline) { @@ -2549,6 +2567,9 @@ static BcStatus bc_num_print(BcNum *n, bool newline) return s; } +#if ERRORS_ARE_FATAL +# define bc_num_print(...) (bc_num_print(__VA_ARGS__), BC_STATUS_SUCCESS) +#endif static FAST_FUNC BcStatus bc_num_add(BcNum *a, BcNum *b, BcNum *c, size_t scale) { @@ -2787,6 +2808,9 @@ static BcStatus bc_func_insert(BcFunc *f, char *name, bool var) return BC_STATUS_SUCCESS; } +#if ERRORS_ARE_FATAL +# define bc_func_insert(...) (bc_func_insert(__VA_ARGS__), BC_STATUS_SUCCESS) +#endif #endif static void bc_func_init(BcFunc *f) @@ -2992,6 +3016,9 @@ static BcStatus bc_lex_number(BcLex *l, char start) return BC_STATUS_SUCCESS; } +#if ERRORS_ARE_FATAL +# define bc_lex_number(...) (bc_lex_number(__VA_ARGS__), BC_STATUS_SUCCESS) +#endif static BcStatus bc_lex_name(BcLex *l) { @@ -5410,8 +5437,6 @@ static BcVec* bc_program_search(char *id, bool var) static BcStatus bc_program_num(BcResult *r, BcNum **num, bool hex) { - BcStatus s = BC_STATUS_SUCCESS; - switch (r->t) { case BC_RESULT_STR: @@ -5426,6 +5451,7 @@ static BcStatus bc_program_num(BcResult *r, BcNum **num, bool hex) case BC_RESULT_CONSTANT: { + BcStatus s; char **str = bc_vec_item(&G.prog.consts, r->d.id.idx); size_t base_t, len = strlen(*str); BcNum *base; @@ -5480,8 +5506,11 @@ static BcStatus bc_program_num(BcResult *r, BcNum **num, bool hex) } } - return s; + return BC_STATUS_SUCCESS; } +#if ERRORS_ARE_FATAL +# define bc_program_num(...) (bc_program_num(__VA_ARGS__), BC_STATUS_SUCCESS) +#endif static BcStatus bc_program_binOpPrep(BcResult **l, BcNum **ln, BcResult **r, BcNum **rn, bool assign) @@ -5544,6 +5573,9 @@ static BcStatus bc_program_prep(BcResult **r, BcNum **n) return s; } +#if ERRORS_ARE_FATAL +# define bc_program_prep(...) (bc_program_prep(__VA_ARGS__), BC_STATUS_SUCCESS) +#endif static void bc_program_retire(BcResult *r, BcResultType t) { @@ -5744,7 +5776,7 @@ static void bc_program_printString(const char *str) static BcStatus bc_program_print(char inst, size_t idx) { - BcStatus s = BC_STATUS_SUCCESS; + BcStatus s; BcResult *r; BcNum *num; bool pop = inst != BC_INST_PRINT; @@ -5786,6 +5818,9 @@ static BcStatus bc_program_print(char inst, size_t idx) return s; } +#if ERRORS_ARE_FATAL +# define bc_program_print(...) (bc_program_print(__VA_ARGS__), BC_STATUS_SUCCESS) +#endif static BcStatus bc_program_negate(void) { @@ -5804,6 +5839,9 @@ static BcStatus bc_program_negate(void) return s; } +#if ERRORS_ARE_FATAL +# define bc_program_negate(...) (bc_program_negate(__VA_ARGS__), BC_STATUS_SUCCESS) +#endif static BcStatus bc_program_logical(char inst) { @@ -6120,6 +6158,9 @@ err: if (s) free(r.d.id.name); return s; } +#if ERRORS_ARE_FATAL +# define bc_program_pushArray(...) (bc_program_pushArray(__VA_ARGS__), BC_STATUS_SUCCESS) +#endif #if ENABLE_BC static BcStatus bc_program_incdec(char inst) @@ -6153,6 +6194,9 @@ static BcStatus bc_program_incdec(char inst) return s; } +#if ERRORS_ARE_FATAL +# define bc_program_incdec(...) (bc_program_incdec(__VA_ARGS__), BC_STATUS_SUCCESS) +#endif static BcStatus bc_program_call(char *code, size_t *idx) { @@ -6444,9 +6488,9 @@ static BcStatus bc_program_asciify(void) c = str2[0]; } - str = xmalloc(2); + str = xzalloc(2); str[0] = c; - str[1] = '\0'; + //str[1] = '\0'; - already is str2 = xstrdup(str); bc_program_addFunc(str2, &idx); @@ -6527,6 +6571,9 @@ static BcStatus bc_program_nquit(void) return s; } +#if ERRORS_ARE_FATAL +# define bc_program_nquit(...) (bc_program_nquit(__VA_ARGS__), BC_STATUS_SUCCESS) +#endif static BcStatus bc_program_execStr(char *code, size_t *bgn, bool cond) @@ -6689,7 +6736,7 @@ static BcStatus bc_program_exec(void) bool cond = false; while (ip->idx < func->code.len) { - BcStatus s; + BcStatus s = BC_STATUS_SUCCESS; char inst = code[(ip->idx)++]; switch (inst) {