diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-26 20:02:09 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-26 20:02:27 +0100 |
commit | f706a18f33a5e6360cd7567c6c5fc9714be3ed39 (patch) | |
tree | d3b154a5451c06183050476e1efb5862dd5fe7b5 | |
parent | 1c69ec1597f0f3ddb8123e9122cd7737debd261c (diff) | |
download | busybox-w32-f706a18f33a5e6360cd7567c6c5fc9714be3ed39.tar.gz busybox-w32-f706a18f33a5e6360cd7567c6c5fc9714be3ed39.tar.bz2 busybox-w32-f706a18f33a5e6360cd7567c6c5fc9714be3ed39.zip |
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 5b79b2db1..2569967d6 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -803,8 +803,6 @@ struct globals { | |||
803 | #define IS_BC (ENABLE_BC && (!ENABLE_DC || applet_name[0] == 'b')) | 803 | #define IS_BC (ENABLE_BC && (!ENABLE_DC || applet_name[0] == 'b')) |
804 | #define IS_DC (ENABLE_DC && (!ENABLE_BC || applet_name[0] != 'b')) | 804 | #define IS_DC (ENABLE_DC && (!ENABLE_BC || applet_name[0] != 'b')) |
805 | 805 | ||
806 | #define BC_PARSE_STREND (0xff) | ||
807 | |||
808 | #if ENABLE_BC | 806 | #if ENABLE_BC |
809 | # define BC_PARSE_REL (1 << 0) | 807 | # define BC_PARSE_REL (1 << 0) |
810 | # define BC_PARSE_PRINT (1 << 1) | 808 | # define BC_PARSE_PRINT (1 << 1) |
@@ -3434,16 +3432,16 @@ static BC_STATUS zdc_lex_token(void) | |||
3434 | 3432 | ||
3435 | static void bc_parse_push(char i) | 3433 | static void bc_parse_push(char i) |
3436 | { | 3434 | { |
3437 | BcParse *p = &G.prs; | 3435 | BcVec *code = &G.prs.func->code; |
3438 | dbg_compile("%s:%d pushing bytecode %zd:%d", __func__, __LINE__, p->func->code.len, i); | 3436 | dbg_compile("%s:%d pushing bytecode %zd:%d", __func__, __LINE__, code->len, i); |
3439 | bc_vec_pushByte(&p->func->code, i); | 3437 | bc_vec_pushByte(code, i); |
3440 | } | 3438 | } |
3441 | 3439 | ||
3442 | static void bc_parse_pushName(char *name) | 3440 | static void bc_parse_pushName(char *name) |
3443 | { | 3441 | { |
3444 | while (*name) | 3442 | do { |
3445 | bc_parse_push(*name++); | 3443 | bc_parse_push(*name); |
3446 | bc_parse_push(BC_PARSE_STREND); | 3444 | } while (*name++); |
3447 | } | 3445 | } |
3448 | 3446 | ||
3449 | static void bc_parse_pushIndex(size_t idx) | 3447 | static void bc_parse_pushIndex(size_t idx) |
@@ -4895,7 +4893,7 @@ static BC_STATUS zdc_parse_cond(uint8_t inst) | |||
4895 | if (s) RETURN_STATUS(s); | 4893 | if (s) RETURN_STATUS(s); |
4896 | s = zbc_lex_next(); | 4894 | s = zbc_lex_next(); |
4897 | } else { | 4895 | } else { |
4898 | bc_parse_push(BC_PARSE_STREND); | 4896 | bc_parse_push('\0'); |
4899 | } | 4897 | } |
4900 | 4898 | ||
4901 | RETURN_STATUS(s); | 4899 | RETURN_STATUS(s); |
@@ -5271,22 +5269,10 @@ static size_t bc_program_index(char *code, size_t *bgn) | |||
5271 | 5269 | ||
5272 | static char *bc_program_name(char *code, size_t *bgn) | 5270 | static char *bc_program_name(char *code, size_t *bgn) |
5273 | { | 5271 | { |
5274 | size_t i; | ||
5275 | char *s; | ||
5276 | |||
5277 | code += *bgn; | 5272 | code += *bgn; |
5278 | s = xmalloc(strchr(code, BC_PARSE_STREND) - code + 1); | 5273 | *bgn += strlen(code) + 1; |
5279 | i = 0; | ||
5280 | for (;;) { | ||
5281 | char c = *code++; | ||
5282 | if (c == BC_PARSE_STREND) | ||
5283 | break; | ||
5284 | s[i++] = c; | ||
5285 | } | ||
5286 | s[i] = '\0'; | ||
5287 | *bgn += i + 1; | ||
5288 | 5274 | ||
5289 | return s; | 5275 | return xstrdup(code); |
5290 | } | 5276 | } |
5291 | 5277 | ||
5292 | static void bc_program_printString(const char *str) | 5278 | 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) | |||
6305 | char *then_name = bc_program_name(code, bgn); | 6291 | char *then_name = bc_program_name(code, bgn); |
6306 | char *else_name = NULL; | 6292 | char *else_name = NULL; |
6307 | 6293 | ||
6308 | if (code[*bgn] == BC_PARSE_STREND) | 6294 | if (code[*bgn] == '\0') |
6309 | (*bgn) += 1; | 6295 | (*bgn) += 1; |
6310 | else | 6296 | else |
6311 | else_name = bc_program_name(code, bgn); | 6297 | else_name = bc_program_name(code, bgn); |