aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-12 16:44:34 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-12 16:44:34 +0100
commitc2da68e896d4253466bed202e71bae7b9b2aeec9 (patch)
tree890bab87913e480fd0734dcc4e985b47a1f9021e /miscutils
parent26819db9a3f029c1abaaf596fe1889315a203122 (diff)
downloadbusybox-c2da68e896d4253466bed202e71bae7b9b2aeec9.tar.gz
bc: optimize bc_parse_pushIndex()
function old new delta bc_parse_pushIndex 80 68 -12 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/bc.c21
1 files 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)