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-f6c1da5ff38c7f1cf3f3d04875330e56d0937894.tar.gz
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;
struct BcProgram;
-typedef void (*BcParseInit)(struct BcParse *, struct BcProgram *, size_t);
typedef BcStatus (*BcParseParse)(struct BcParse *);
-typedef BcStatus (*BcParseExpr)(struct BcParse *, uint8_t);
typedef struct BcParse {
@@ -724,7 +722,6 @@ static BcStatus bc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next);
static BcStatus dc_lex_token(BcLex *l);
-static void dc_parse_init(BcParse *p, struct BcProgram *prog, size_t func);
static BcStatus dc_parse_expr(BcParse *p, uint8_t flags);
#endif // ENABLE_DC
@@ -768,9 +765,6 @@ typedef struct BcProgram {
size_t nchars;
- BcParseInit parse_init;
- BcParseExpr parse_expr;
-
} BcProgram;
#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)
}
#endif // ENABLE_DC
+static void common_parse_init(BcParse *p, BcProgram *prog, size_t func)
+{
+ if (IS_BC) {
+ bc_parse_init(p, prog, func);
+ } else {
+ dc_parse_init(p, prog, func);
+ }
+}
+
+static BcStatus common_parse_expr(BcParse *p, uint8_t flags)
+{
+ if (IS_BC) {
+ return bc_parse_expression(p, flags);
+ } else {
+ return dc_parse_expr(p, flags);
+ }
+}
+
static void bc_program_search(BcProgram *p, char *id, BcVec **ret, bool var)
{
BcStatus s;
@@ -5469,13 +5481,12 @@ static BcStatus bc_program_read(void)
s = bc_read_line(&buf, "read> ");
if (s) goto io_err;
- p->parse_init(&parse, p, BC_PROG_READ);
+ common_parse_init(&parse, p, BC_PROG_READ);
bc_lex_file(&parse.l, bc_program_stdin_name);
s = bc_parse_text(&parse, buf.v);
if (s) goto exec_err;
-/// replace by IS_BC selection
- s = p->parse_expr(&parse, BC_PARSE_NOREAD);
+ s = common_parse_expr(&parse, BC_PARSE_NOREAD);
if (s) goto exec_err;
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,
f = bc_vec_item(&p->fns, fidx);
if (f->code.len == 0) {
-/// replace by IS_BC selection
- p->parse_init(&prs, p, fidx);
+ common_parse_init(&prs, p, fidx);
s = bc_parse_text(&prs, *str);
if (s) goto err;
-/// replace by IS_BC selection
- s = p->parse_expr(&prs, BC_PARSE_NOCALL);
+ s = common_parse_expr(&prs, BC_PARSE_NOCALL);
if (s) goto err;
if (prs.l.t.t != BC_LEX_EOF) {
@@ -7212,13 +7221,6 @@ static void bc_program_init(size_t line_len)
/* G.prog.nchars = G.prog.scale = 0; - already is */
G.prog.len = line_len;
- if (IS_BC) {
- G.prog.parse_init = bc_parse_init;
- G.prog.parse_expr = bc_parse_expression;
- } else {
- G.prog.parse_init = dc_parse_init;
- G.prog.parse_expr = dc_parse_expr;
- }
bc_num_init(&G.prog.ib, BC_NUM_DEF_SIZE);
bc_num_ten(&G.prog.ib);
@@ -7267,7 +7269,6 @@ static void bc_program_init(size_t line_len)
static void bc_vm_init(const char *env_len)
{
- BcParseInit init;
size_t len = bc_vm_envLen(env_len);
#if ENABLE_FEATURE_BC_SIGNALS
@@ -7280,13 +7281,14 @@ static void bc_vm_init(const char *env_len)
if (getenv("POSIXLY_CORRECT"))
G.flags |= BC_FLAG_S;
bc_vm_envArgs();
- init = bc_parse_init;
- } else {
- init = dc_parse_init;
}
bc_program_init(len);
- init(&G.prs, &G.prog, BC_PROG_MAIN);
+ if (IS_BC) {
+ bc_parse_init(&G.prs, &G.prog, BC_PROG_MAIN);
+ } else {
+ dc_parse_init(&G.prs, &G.prog, BC_PROG_MAIN);
+ }
}
static BcStatus bc_vm_run(int argc, char *argv[],