bc: code shrink - convert two macros to functions
function old new delta
bc_program_printStream - 185 +185
bc_program_pushArray - 147 +147
bc_program_exec 4132 4219 +87
bc_vec_pop - 27 +27
bc_vec_top - 13 +13
bc_num_ulong 92 103 +11
bc_vm_run 1905 1903 -2
bc_vm_process 94 92 -2
bc_program_reset 72 70 -2
bc_program_prep 93 91 -2
bc_program_call 366 364 -2
bc_parse_startBody 47 45 -2
bc_parse_parse 464 462 -2
bc_parse_else 137 135 -2
bc_parse_body 118 116 -2
bc_program_num 1129 1125 -4
bc_parse_text 147 143 -4
bc_program_retire 40 35 -5
bc_program_print 778 773 -5
bc_program_modexp 746 741 -5
bc_program_pushVar 215 208 -7
bc_program_copyToVar 323 316 -7
bc_parse_operator 184 177 -7
bc_parse_noElse 65 56 -9
bc_program_binOpRetire 56 46 -10
bc_parse_stmt 2271 2261 -10
bc_program_execStr 543 528 -15
bc_program_assignStr 161 146 -15
bc_parse_expr_empty_ok 2178 2157 -21
bc_parse_endBody 420 375 -45
bc_program_asciify 464 - -464
------------------------------------------------------------------------------
(add/remove: 4/1 grow/shrink: 2/24 up/down: 470/-651) Total: -181 bytes
text data bss dec hex filename
987227 485 7296 995008 f2ec0 busybox_old
987046 485 7296 994827 f2e0b busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
diff --git a/miscutils/bc.c b/miscutils/bc.c
index f936ad6..3d53db7 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -1069,8 +1069,12 @@
}
}
-#define bc_vec_pop(v) (bc_vec_npop((v), 1))
-#define bc_vec_top(v) (bc_vec_item_rev((v), 0))
+static void bc_vec_pop(BcVec *v)
+{
+ v->len--;
+ if (v->dtor)
+ v->dtor(v->v + (v->size * v->len));
+}
static void bc_vec_npop(BcVec *v, size_t n)
{
@@ -1094,8 +1098,6 @@
v->len += 1;
}
-#define bc_parse_push(p, i) bc_vec_pushByte(&(p)->func->code, (char) (i))
-
static void bc_vec_pushByte(BcVec *v, char data)
{
bc_vec_push(v, &data);
@@ -1159,6 +1161,11 @@
return v->v + v->size * (v->len - idx - 1);
}
+static void *bc_vec_top(const BcVec *v)
+{
+ return v->v + v->size * (v->len - 1);
+}
+
static void bc_vec_free(void *vec)
{
BcVec *v = (BcVec *) vec;
@@ -3530,6 +3537,8 @@
p->func = bc_vec_item(&G.prog.fns, p->fidx);
}
+#define bc_parse_push(p, i) bc_vec_pushByte(&(p)->func->code, (char) (i))
+
static void bc_parse_pushName(BcParse *p, char *name)
{
size_t i = 0, len = strlen(name);