diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-19 13:19:44 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-19 13:20:02 +0100 |
commit | e3d3d2067dd535224e7a6f713107a38c3c7e18cd (patch) | |
tree | 0b777504a387e68c2146d6417e2676bcf9a3aba7 | |
parent | 4796a1d5375aac790564a38289d5b238a81e8efb (diff) | |
download | busybox-e3d3d2067dd535224e7a6f713107a38c3c7e18cd.tar.gz |
bc: remove redundant strdup+free in zbc_parse_call()
function old new delta
zbc_parse_name 527 482 -45
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-45) Total: -45 bytes
text data bss dec hex filename
981541 485 7296 989322 f188a busybox_old
981486 485 7296 989267 f1853 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 8ddedf337..afc09a30b 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c @@ -1210,7 +1210,7 @@ static size_t bc_map_find(const BcVec *v, const void *ptr) if (result == 0) return mid; - else if (result < 0) + if (result < 0) high = mid; else low = mid + 1; @@ -3441,6 +3441,7 @@ static BC_STATUS zdc_lex_token(BcLex *l) static void bc_program_addFunc(char *name, size_t *idx); +// Note: takes ownership of 'name' (must be malloced) static void bc_parse_addFunc(BcParse *p, char *name, size_t *idx) { bc_program_addFunc(name, idx); @@ -3494,7 +3495,7 @@ static void bc_parse_pushJUMP_ZERO(BcParse *p, size_t idx) bc_parse_pushIndex(p, idx); } -static void bc_parse_number(BcParse *p) +static void bc_parse_pushNUM(BcParse *p) { char *num = xstrdup(p->l.t.v.v); size_t idx = G.prog.consts.len; @@ -3719,6 +3720,7 @@ static BC_STATUS zbc_parse_params(BcParse *p, uint8_t flags) } #define zbc_parse_params(...) (zbc_parse_params(__VA_ARGS__) COMMA_SUCCESS) +// Note: takes ownership of 'name' (must be malloced) static BC_STATUS zbc_parse_call(BcParse *p, char *name, uint8_t flags) { BcStatus s; @@ -3738,10 +3740,9 @@ static BC_STATUS zbc_parse_call(BcParse *p, char *name, uint8_t flags) idx = bc_map_index(&G.prog.fn_map, &entry); if (idx == BC_VEC_INVALID_IDX) { - name = xstrdup(entry.name); + // No such function exist, create an empty one bc_parse_addFunc(p, name, &idx); idx = bc_map_index(&G.prog.fn_map, &entry); - free(entry.name); } else free(name); @@ -4628,7 +4629,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) case BC_LEX_NUMBER: if (BC_PARSE_LEAF(prev, rprn)) return bc_error_bad_expression(); - bc_parse_number(p); + bc_parse_pushNUM(p); nexprs++; prev = BC_INST_NUM; paren_expr = get_token = true; @@ -4829,7 +4830,7 @@ static BC_STATUS zdc_parse_token(BcParse *p, BcLexType t, uint8_t flags) if (p->l.t.t != BC_LEX_NUMBER) RETURN_STATUS(bc_error_bad_token()); } - bc_parse_number(p); + bc_parse_pushNUM(p); if (t == BC_LEX_NEG) bc_parse_push(p, BC_INST_NEG); get_token = true; break; @@ -4964,15 +4965,15 @@ static BC_STATUS zbc_program_num(BcResult *r, BcNum **num, bool hex) break; case BC_RESULT_CONSTANT: { BcStatus s; - char **str = bc_vec_item(&G.prog.consts, r->d.id.idx); + char *str = *(char**)bc_vec_item(&G.prog.consts, r->d.id.idx); unsigned base_t; - size_t len = strlen(*str); + size_t len = strlen(str); bc_num_init(&r->d.n, len); hex = hex && len == 1; base_t = hex ? 16 : G.prog.ib_t; - s = zbc_num_parse(&r->d.n, *str, base_t); + s = zbc_num_parse(&r->d.n, str, base_t); if (s) { bc_num_free(&r->d.n); @@ -6317,6 +6318,7 @@ static void bc_program_pushGlobal(char inst) bc_vec_push(&G.prog.results, &res); } +// Note: takes ownership of 'name' (must be malloced) static void bc_program_addFunc(char *name, size_t *idx) { BcId entry, *entry_ptr; |