diff options
author | Denys Vlasenko | 2018-12-26 20:02:09 +0100 |
---|---|---|
committer | Denys Vlasenko | 2018-12-26 20:02:27 +0100 |
commit | f706a18f33a5e6360cd7567c6c5fc9714be3ed39 (patch) | |
tree | d3b154a5451c06183050476e1efb5862dd5fe7b5 | |
parent | 1c69ec1597f0f3ddb8123e9122cd7737debd261c (diff) | |
download | busybox-f706a18f33a5e6360cd7567c6c5fc9714be3ed39.zip busybox-f706a18f33a5e6360cd7567c6c5fc9714be3ed39.tar.gz |
bc: use '\0' insteads of 0xff (BC_PARSE_STREND) as name terminator
function old new delta
zdc_program_printStream - 146 +146
zbc_program_exec 4003 4016 +13
zdc_parse_expr 473 470 -3
bc_parse_pushName 31 20 -11
bc_program_name 63 34 -29
zbc_program_pushArray 147 - -147
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/3 up/down: 159/-190) Total: -31 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 34 |
1 files changed, 10 insertions, 24 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 5b79b2d..2569967 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c @@ -803,8 +803,6 @@ struct globals { #define IS_BC (ENABLE_BC && (!ENABLE_DC || applet_name[0] == 'b')) #define IS_DC (ENABLE_DC && (!ENABLE_BC || applet_name[0] != 'b')) -#define BC_PARSE_STREND (0xff) - #if ENABLE_BC # define BC_PARSE_REL (1 << 0) # define BC_PARSE_PRINT (1 << 1) @@ -3434,16 +3432,16 @@ static BC_STATUS zdc_lex_token(void) static void bc_parse_push(char i) { - BcParse *p = &G.prs; - dbg_compile("%s:%d pushing bytecode %zd:%d", __func__, __LINE__, p->func->code.len, i); - bc_vec_pushByte(&p->func->code, i); + BcVec *code = &G.prs.func->code; + dbg_compile("%s:%d pushing bytecode %zd:%d", __func__, __LINE__, code->len, i); + bc_vec_pushByte(code, i); } static void bc_parse_pushName(char *name) { - while (*name) - bc_parse_push(*name++); - bc_parse_push(BC_PARSE_STREND); + do { + bc_parse_push(*name); + } while (*name++); } static void bc_parse_pushIndex(size_t idx) @@ -4895,7 +4893,7 @@ static BC_STATUS zdc_parse_cond(uint8_t inst) if (s) RETURN_STATUS(s); s = zbc_lex_next(); } else { - bc_parse_push(BC_PARSE_STREND); + bc_parse_push('\0'); } RETURN_STATUS(s); @@ -5271,22 +5269,10 @@ static size_t bc_program_index(char *code, size_t *bgn) static char *bc_program_name(char *code, size_t *bgn) { - size_t i; - char *s; - code += *bgn; - s = xmalloc(strchr(code, BC_PARSE_STREND) - code + 1); - i = 0; - for (;;) { - char c = *code++; - if (c == BC_PARSE_STREND) - break; - s[i++] = c; - } - s[i] = '\0'; - *bgn += i + 1; + *bgn += strlen(code) + 1; - return s; + return xstrdup(code); } static void bc_program_printString(const char *str) @@ -6305,7 +6291,7 @@ static BC_STATUS zdc_program_execStr(char *code, size_t *bgn, bool cond) char *then_name = bc_program_name(code, bgn); char *else_name = NULL; - if (code[*bgn] == BC_PARSE_STREND) + if (code[*bgn] == '\0') (*bgn) += 1; else else_name = bc_program_name(code, bgn); |