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>
This commit is contained in:
Denys Vlasenko 2018-12-16 20:32:58 +01:00
parent 563d93c9a4
commit e6c40c48d9

View File

@ -3529,12 +3529,9 @@ static void bc_parse_push(BcParse *p, char i)
static void bc_parse_pushName(BcParse *p, char *name)
{
size_t i = 0, len = strlen(name);
for (; i < len; ++i) bc_parse_push(p, name[i]);
while (*name)
bc_parse_push(p, *name++);
bc_parse_push(p, BC_PARSE_STREND);
free(name);
}
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)
if (s) goto err;
bc_parse_push(p, *type);
bc_parse_pushName(p, name);
free(name);
}
else if (p->l.t.t == BC_LEX_LPAREN) {
if (flags & BC_PARSE_NOCALL) {
@ -3840,6 +3838,7 @@ static BC_STATUS zbc_parse_name(BcParse *p, BcInst *type, uint8_t flags)
*type = BC_INST_VAR;
bc_parse_push(p, BC_INST_VAR);
bc_parse_pushName(p, name);
free(name);
}
RETURN_STATUS(s);
@ -4970,14 +4969,12 @@ static BC_STATUS zbc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next)
static BC_STATUS zdc_parse_register(BcParse *p)
{
BcStatus s;
char *name;
s = zbc_lex_next(&p->l);
if (s) RETURN_STATUS(s);
if (p->l.t.t != BC_LEX_NAME) RETURN_STATUS(bc_error_bad_token());
name = xstrdup(p->l.t.v.v);
bc_parse_pushName(p, name);
bc_parse_pushName(p, p->l.t.v.v);
RETURN_STATUS(s);
}