diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-16 20:32:58 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-16 20:32:58 +0100 |
commit | e6c40c48d96169ff27471c63c33e568e96fd5b82 (patch) | |
tree | 60c514bebe1dcf5ef568351492a222495a4b7e86 | |
parent | 563d93c9a4e2a784dfbec6703c572fb88eb99332 (diff) | |
download | busybox-w32-e6c40c48d96169ff27471c63c33e568e96fd5b82.tar.gz busybox-w32-e6c40c48d96169ff27471c63c33e568e96fd5b82.tar.bz2 busybox-w32-e6c40c48d96169ff27471c63c33e568e96fd5b82.zip |
bc: simplify bc_parse_pushName(), do not free name in it - avoids one strdup
function old new delta
zbc_parse_name 511 509 -2
zdc_parse_register 50 43 -7
bc_parse_pushName 61 39 -22
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-31) Total: -31 bytes
text data bss dec hex filename
982183 485 7296 989964 f1b0c busybox_old
982152 485 7296 989933 f1aed busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 8aaeeaf9f..6e39aeed3 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -3529,12 +3529,9 @@ static void bc_parse_push(BcParse *p, char i) | |||
3529 | 3529 | ||
3530 | static void bc_parse_pushName(BcParse *p, char *name) | 3530 | static void bc_parse_pushName(BcParse *p, char *name) |
3531 | { | 3531 | { |
3532 | size_t i = 0, len = strlen(name); | 3532 | while (*name) |
3533 | 3533 | bc_parse_push(p, *name++); | |
3534 | for (; i < len; ++i) bc_parse_push(p, name[i]); | ||
3535 | bc_parse_push(p, BC_PARSE_STREND); | 3534 | bc_parse_push(p, BC_PARSE_STREND); |
3536 | |||
3537 | free(name); | ||
3538 | } | 3535 | } |
3539 | 3536 | ||
3540 | static void bc_parse_pushIndex(BcParse *p, size_t idx) | 3537 | static void bc_parse_pushIndex(BcParse *p, size_t idx) |
@@ -3828,6 +3825,7 @@ static BC_STATUS zbc_parse_name(BcParse *p, BcInst *type, uint8_t flags) | |||
3828 | if (s) goto err; | 3825 | if (s) goto err; |
3829 | bc_parse_push(p, *type); | 3826 | bc_parse_push(p, *type); |
3830 | bc_parse_pushName(p, name); | 3827 | bc_parse_pushName(p, name); |
3828 | free(name); | ||
3831 | } | 3829 | } |
3832 | else if (p->l.t.t == BC_LEX_LPAREN) { | 3830 | else if (p->l.t.t == BC_LEX_LPAREN) { |
3833 | if (flags & BC_PARSE_NOCALL) { | 3831 | if (flags & BC_PARSE_NOCALL) { |
@@ -3840,6 +3838,7 @@ static BC_STATUS zbc_parse_name(BcParse *p, BcInst *type, uint8_t flags) | |||
3840 | *type = BC_INST_VAR; | 3838 | *type = BC_INST_VAR; |
3841 | bc_parse_push(p, BC_INST_VAR); | 3839 | bc_parse_push(p, BC_INST_VAR); |
3842 | bc_parse_pushName(p, name); | 3840 | bc_parse_pushName(p, name); |
3841 | free(name); | ||
3843 | } | 3842 | } |
3844 | 3843 | ||
3845 | RETURN_STATUS(s); | 3844 | RETURN_STATUS(s); |
@@ -4970,14 +4969,12 @@ static BC_STATUS zbc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next) | |||
4970 | static BC_STATUS zdc_parse_register(BcParse *p) | 4969 | static BC_STATUS zdc_parse_register(BcParse *p) |
4971 | { | 4970 | { |
4972 | BcStatus s; | 4971 | BcStatus s; |
4973 | char *name; | ||
4974 | 4972 | ||
4975 | s = zbc_lex_next(&p->l); | 4973 | s = zbc_lex_next(&p->l); |
4976 | if (s) RETURN_STATUS(s); | 4974 | if (s) RETURN_STATUS(s); |
4977 | if (p->l.t.t != BC_LEX_NAME) RETURN_STATUS(bc_error_bad_token()); | 4975 | if (p->l.t.t != BC_LEX_NAME) RETURN_STATUS(bc_error_bad_token()); |
4978 | 4976 | ||
4979 | name = xstrdup(p->l.t.v.v); | 4977 | bc_parse_pushName(p, p->l.t.v.v); |
4980 | bc_parse_pushName(p, name); | ||
4981 | 4978 | ||
4982 | RETURN_STATUS(s); | 4979 | RETURN_STATUS(s); |
4983 | } | 4980 | } |