aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-02 17:36:00 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-05 15:43:35 +0100
commitf6c1da5ff38c7f1cf3f3d04875330e56d0937894 (patch)
tree592bc513f3a0adc958b987eae6edc2880ee676e8
parent785e4b30570ddd772c38f3f8693b686430fc35a3 (diff)
downloadbusybox-w32-f6c1da5ff38c7f1cf3f3d04875330e56d0937894.tar.gz
busybox-w32-f6c1da5ff38c7f1cf3f3d04875330e56d0937894.tar.bz2
busybox-w32-f6c1da5ff38c7f1cf3f3d04875330e56d0937894.zip
bc: select parse_init() and parse_expr() using IS_BC, not function pointers
function old new delta common_parse_expr - 62 +62 common_parse_init - 29 +29 dc_parse_parse 53 52 -1 dc_parse_expr 723 719 -4 bc_program_execStr 606 594 -12 dc_parse_init 33 18 -15 bc_parse_init 33 18 -15 bc_parse_expression 39 - -39 bc_vm_run 1923 1872 -51 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 0/6 up/down: 91/-137) Total: -46 bytes text data bss dec hex filename 988774 485 7296 996555 f34cb busybox_old 988728 485 7296 996509 f349d busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c52
1 files changed, 27 insertions, 25 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 117318bfa..18d388bd3 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -662,9 +662,7 @@ struct BcParse;
662 662
663struct BcProgram; 663struct BcProgram;
664 664
665typedef void (*BcParseInit)(struct BcParse *, struct BcProgram *, size_t);
666typedef BcStatus (*BcParseParse)(struct BcParse *); 665typedef BcStatus (*BcParseParse)(struct BcParse *);
667typedef BcStatus (*BcParseExpr)(struct BcParse *, uint8_t);
668 666
669typedef struct BcParse { 667typedef struct BcParse {
670 668
@@ -724,7 +722,6 @@ static BcStatus bc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next);
724 722
725static BcStatus dc_lex_token(BcLex *l); 723static BcStatus dc_lex_token(BcLex *l);
726 724
727static void dc_parse_init(BcParse *p, struct BcProgram *prog, size_t func);
728static BcStatus dc_parse_expr(BcParse *p, uint8_t flags); 725static BcStatus dc_parse_expr(BcParse *p, uint8_t flags);
729 726
730#endif // ENABLE_DC 727#endif // ENABLE_DC
@@ -768,9 +765,6 @@ typedef struct BcProgram {
768 765
769 size_t nchars; 766 size_t nchars;
770 767
771 BcParseInit parse_init;
772 BcParseExpr parse_expr;
773
774} BcProgram; 768} BcProgram;
775 769
776#define BC_PROG_STACK(s, n) ((s)->len >= ((size_t) n)) 770#define BC_PROG_STACK(s, n) ((s)->len >= ((size_t) n))
@@ -5259,6 +5253,24 @@ static void dc_parse_init(BcParse *p, BcProgram *prog, size_t func)
5259} 5253}
5260#endif // ENABLE_DC 5254#endif // ENABLE_DC
5261 5255
5256static void common_parse_init(BcParse *p, BcProgram *prog, size_t func)
5257{
5258 if (IS_BC) {
5259 bc_parse_init(p, prog, func);
5260 } else {
5261 dc_parse_init(p, prog, func);
5262 }
5263}
5264
5265static BcStatus common_parse_expr(BcParse *p, uint8_t flags)
5266{
5267 if (IS_BC) {
5268 return bc_parse_expression(p, flags);
5269 } else {
5270 return dc_parse_expr(p, flags);
5271 }
5272}
5273
5262static void bc_program_search(BcProgram *p, char *id, BcVec **ret, bool var) 5274static void bc_program_search(BcProgram *p, char *id, BcVec **ret, bool var)
5263{ 5275{
5264 BcStatus s; 5276 BcStatus s;
@@ -5469,13 +5481,12 @@ static BcStatus bc_program_read(void)
5469 s = bc_read_line(&buf, "read> "); 5481 s = bc_read_line(&buf, "read> ");
5470 if (s) goto io_err; 5482 if (s) goto io_err;
5471 5483
5472 p->parse_init(&parse, p, BC_PROG_READ); 5484 common_parse_init(&parse, p, BC_PROG_READ);
5473 bc_lex_file(&parse.l, bc_program_stdin_name); 5485 bc_lex_file(&parse.l, bc_program_stdin_name);
5474 5486
5475 s = bc_parse_text(&parse, buf.v); 5487 s = bc_parse_text(&parse, buf.v);
5476 if (s) goto exec_err; 5488 if (s) goto exec_err;
5477/// replace by IS_BC selection 5489 s = common_parse_expr(&parse, BC_PARSE_NOREAD);
5478 s = p->parse_expr(&parse, BC_PARSE_NOREAD);
5479 if (s) goto exec_err; 5490 if (s) goto exec_err;
5480 5491
5481 if (parse.l.t.t != BC_LEX_NLINE && parse.l.t.t != BC_LEX_EOF) { 5492 if (parse.l.t.t != BC_LEX_NLINE && parse.l.t.t != BC_LEX_EOF) {
@@ -6453,12 +6464,10 @@ static BcStatus bc_program_execStr(char *code, size_t *bgn,
6453 f = bc_vec_item(&p->fns, fidx); 6464 f = bc_vec_item(&p->fns, fidx);
6454 6465
6455 if (f->code.len == 0) { 6466 if (f->code.len == 0) {
6456/// replace by IS_BC selection 6467 common_parse_init(&prs, p, fidx);
6457 p->parse_init(&prs, p, fidx);
6458 s = bc_parse_text(&prs, *str); 6468 s = bc_parse_text(&prs, *str);
6459 if (s) goto err; 6469 if (s) goto err;
6460/// replace by IS_BC selection 6470 s = common_parse_expr(&prs, BC_PARSE_NOCALL);
6461 s = p->parse_expr(&prs, BC_PARSE_NOCALL);
6462 if (s) goto err; 6471 if (s) goto err;
6463 6472
6464 if (prs.l.t.t != BC_LEX_EOF) { 6473 if (prs.l.t.t != BC_LEX_EOF) {
@@ -7212,13 +7221,6 @@ static void bc_program_init(size_t line_len)
7212 7221
7213 /* G.prog.nchars = G.prog.scale = 0; - already is */ 7222 /* G.prog.nchars = G.prog.scale = 0; - already is */
7214 G.prog.len = line_len; 7223 G.prog.len = line_len;
7215 if (IS_BC) {
7216 G.prog.parse_init = bc_parse_init;
7217 G.prog.parse_expr = bc_parse_expression;
7218 } else {
7219 G.prog.parse_init = dc_parse_init;
7220 G.prog.parse_expr = dc_parse_expr;
7221 }
7222 7224
7223 bc_num_init(&G.prog.ib, BC_NUM_DEF_SIZE); 7225 bc_num_init(&G.prog.ib, BC_NUM_DEF_SIZE);
7224 bc_num_ten(&G.prog.ib); 7226 bc_num_ten(&G.prog.ib);
@@ -7267,7 +7269,6 @@ static void bc_program_init(size_t line_len)
7267 7269
7268static void bc_vm_init(const char *env_len) 7270static void bc_vm_init(const char *env_len)
7269{ 7271{
7270 BcParseInit init;
7271 size_t len = bc_vm_envLen(env_len); 7272 size_t len = bc_vm_envLen(env_len);
7272 7273
7273#if ENABLE_FEATURE_BC_SIGNALS 7274#if ENABLE_FEATURE_BC_SIGNALS
@@ -7280,13 +7281,14 @@ static void bc_vm_init(const char *env_len)
7280 if (getenv("POSIXLY_CORRECT")) 7281 if (getenv("POSIXLY_CORRECT"))
7281 G.flags |= BC_FLAG_S; 7282 G.flags |= BC_FLAG_S;
7282 bc_vm_envArgs(); 7283 bc_vm_envArgs();
7283 init = bc_parse_init;
7284 } else {
7285 init = dc_parse_init;
7286 } 7284 }
7287 7285
7288 bc_program_init(len); 7286 bc_program_init(len);
7289 init(&G.prs, &G.prog, BC_PROG_MAIN); 7287 if (IS_BC) {
7288 bc_parse_init(&G.prs, &G.prog, BC_PROG_MAIN);
7289 } else {
7290 dc_parse_init(&G.prs, &G.prog, BC_PROG_MAIN);
7291 }
7290} 7292}
7291 7293
7292static BcStatus bc_vm_run(int argc, char *argv[], 7294static BcStatus bc_vm_run(int argc, char *argv[],