aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-19 13:19:44 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-19 13:20:02 +0100
commite3d3d2067dd535224e7a6f713107a38c3c7e18cd (patch)
tree0b777504a387e68c2146d6417e2676bcf9a3aba7
parent4796a1d5375aac790564a38289d5b238a81e8efb (diff)
downloadbusybox-w32-e3d3d2067dd535224e7a6f713107a38c3c7e18cd.tar.gz
busybox-w32-e3d3d2067dd535224e7a6f713107a38c3c7e18cd.tar.bz2
busybox-w32-e3d3d2067dd535224e7a6f713107a38c3c7e18cd.zip
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.c20
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)
1210 1210
1211 if (result == 0) 1211 if (result == 0)
1212 return mid; 1212 return mid;
1213 else if (result < 0) 1213 if (result < 0)
1214 high = mid; 1214 high = mid;
1215 else 1215 else
1216 low = mid + 1; 1216 low = mid + 1;
@@ -3441,6 +3441,7 @@ static BC_STATUS zdc_lex_token(BcLex *l)
3441 3441
3442static void bc_program_addFunc(char *name, size_t *idx); 3442static void bc_program_addFunc(char *name, size_t *idx);
3443 3443
3444// Note: takes ownership of 'name' (must be malloced)
3444static void bc_parse_addFunc(BcParse *p, char *name, size_t *idx) 3445static void bc_parse_addFunc(BcParse *p, char *name, size_t *idx)
3445{ 3446{
3446 bc_program_addFunc(name, idx); 3447 bc_program_addFunc(name, idx);
@@ -3494,7 +3495,7 @@ static void bc_parse_pushJUMP_ZERO(BcParse *p, size_t idx)
3494 bc_parse_pushIndex(p, idx); 3495 bc_parse_pushIndex(p, idx);
3495} 3496}
3496 3497
3497static void bc_parse_number(BcParse *p) 3498static void bc_parse_pushNUM(BcParse *p)
3498{ 3499{
3499 char *num = xstrdup(p->l.t.v.v); 3500 char *num = xstrdup(p->l.t.v.v);
3500 size_t idx = G.prog.consts.len; 3501 size_t idx = G.prog.consts.len;
@@ -3719,6 +3720,7 @@ static BC_STATUS zbc_parse_params(BcParse *p, uint8_t flags)
3719} 3720}
3720#define zbc_parse_params(...) (zbc_parse_params(__VA_ARGS__) COMMA_SUCCESS) 3721#define zbc_parse_params(...) (zbc_parse_params(__VA_ARGS__) COMMA_SUCCESS)
3721 3722
3723// Note: takes ownership of 'name' (must be malloced)
3722static BC_STATUS zbc_parse_call(BcParse *p, char *name, uint8_t flags) 3724static BC_STATUS zbc_parse_call(BcParse *p, char *name, uint8_t flags)
3723{ 3725{
3724 BcStatus s; 3726 BcStatus s;
@@ -3738,10 +3740,9 @@ static BC_STATUS zbc_parse_call(BcParse *p, char *name, uint8_t flags)
3738 idx = bc_map_index(&G.prog.fn_map, &entry); 3740 idx = bc_map_index(&G.prog.fn_map, &entry);
3739 3741
3740 if (idx == BC_VEC_INVALID_IDX) { 3742 if (idx == BC_VEC_INVALID_IDX) {
3741 name = xstrdup(entry.name); 3743 // No such function exist, create an empty one
3742 bc_parse_addFunc(p, name, &idx); 3744 bc_parse_addFunc(p, name, &idx);
3743 idx = bc_map_index(&G.prog.fn_map, &entry); 3745 idx = bc_map_index(&G.prog.fn_map, &entry);
3744 free(entry.name);
3745 } else 3746 } else
3746 free(name); 3747 free(name);
3747 3748
@@ -4628,7 +4629,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags)
4628 case BC_LEX_NUMBER: 4629 case BC_LEX_NUMBER:
4629 if (BC_PARSE_LEAF(prev, rprn)) 4630 if (BC_PARSE_LEAF(prev, rprn))
4630 return bc_error_bad_expression(); 4631 return bc_error_bad_expression();
4631 bc_parse_number(p); 4632 bc_parse_pushNUM(p);
4632 nexprs++; 4633 nexprs++;
4633 prev = BC_INST_NUM; 4634 prev = BC_INST_NUM;
4634 paren_expr = get_token = true; 4635 paren_expr = get_token = true;
@@ -4829,7 +4830,7 @@ static BC_STATUS zdc_parse_token(BcParse *p, BcLexType t, uint8_t flags)
4829 if (p->l.t.t != BC_LEX_NUMBER) 4830 if (p->l.t.t != BC_LEX_NUMBER)
4830 RETURN_STATUS(bc_error_bad_token()); 4831 RETURN_STATUS(bc_error_bad_token());
4831 } 4832 }
4832 bc_parse_number(p); 4833 bc_parse_pushNUM(p);
4833 if (t == BC_LEX_NEG) bc_parse_push(p, BC_INST_NEG); 4834 if (t == BC_LEX_NEG) bc_parse_push(p, BC_INST_NEG);
4834 get_token = true; 4835 get_token = true;
4835 break; 4836 break;
@@ -4964,15 +4965,15 @@ static BC_STATUS zbc_program_num(BcResult *r, BcNum **num, bool hex)
4964 break; 4965 break;
4965 case BC_RESULT_CONSTANT: { 4966 case BC_RESULT_CONSTANT: {
4966 BcStatus s; 4967 BcStatus s;
4967 char **str = bc_vec_item(&G.prog.consts, r->d.id.idx); 4968 char *str = *(char**)bc_vec_item(&G.prog.consts, r->d.id.idx);
4968 unsigned base_t; 4969 unsigned base_t;
4969 size_t len = strlen(*str); 4970 size_t len = strlen(str);
4970 4971
4971 bc_num_init(&r->d.n, len); 4972 bc_num_init(&r->d.n, len);
4972 4973
4973 hex = hex && len == 1; 4974 hex = hex && len == 1;
4974 base_t = hex ? 16 : G.prog.ib_t; 4975 base_t = hex ? 16 : G.prog.ib_t;
4975 s = zbc_num_parse(&r->d.n, *str, base_t); 4976 s = zbc_num_parse(&r->d.n, str, base_t);
4976 4977
4977 if (s) { 4978 if (s) {
4978 bc_num_free(&r->d.n); 4979 bc_num_free(&r->d.n);
@@ -6317,6 +6318,7 @@ static void bc_program_pushGlobal(char inst)
6317 bc_vec_push(&G.prog.results, &res); 6318 bc_vec_push(&G.prog.results, &res);
6318} 6319}
6319 6320
6321// Note: takes ownership of 'name' (must be malloced)
6320static void bc_program_addFunc(char *name, size_t *idx) 6322static void bc_program_addFunc(char *name, size_t *idx)
6321{ 6323{
6322 BcId entry, *entry_ptr; 6324 BcId entry, *entry_ptr;