[git commit] bc: optimize bc_parse_pushIndex()
Denys Vlasenko
vda.linux at googlemail.com
Wed Dec 12 15:44:34 UTC 2018
commit: https://git.busybox.net/busybox/commit/?id=c2da68e896d4253466bed202e71bae7b9b2aeec9
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
function old new delta
bc_parse_pushIndex 80 68 -12
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
miscutils/bc.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 73c801c44..dc8e5c761 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -3460,16 +3460,23 @@ static void bc_parse_pushName(BcParse *p, char *name)
static void bc_parse_pushIndex(BcParse *p, size_t idx)
{
- unsigned char amt, i, nums[sizeof(size_t)];
+ size_t mask;
+ unsigned amt;
-///oh boy
- for (amt = 0; idx; ++amt) {
- nums[amt] = (char) idx;
- idx = (idx & ((unsigned long) ~(UCHAR_MAX))) >> sizeof(char) * CHAR_BIT;
- }
+ mask = ((size_t)0xff) << (sizeof(idx) * 8 - 8);
+ amt = sizeof(idx);
+ do {
+ if (idx & mask) break;
+ mask >>= 8;
+ amt--;
+ } while (amt != 0);
bc_parse_push(p, amt);
- for (i = 0; i < amt; ++i) bc_parse_push(p, nums[i]);
+
+ while (idx != 0) {
+ bc_parse_push(p, (unsigned char)idx);
+ idx >>= 8;
+ }
}
static void bc_parse_number(BcParse *p, BcInst *prev, size_t *nexs)
More information about the busybox-cvs
mailing list