diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-12 16:44:34 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-12 16:44:34 +0100 |
commit | c2da68e896d4253466bed202e71bae7b9b2aeec9 (patch) | |
tree | 890bab87913e480fd0734dcc4e985b47a1f9021e | |
parent | 26819db9a3f029c1abaaf596fe1889315a203122 (diff) | |
download | busybox-w32-c2da68e896d4253466bed202e71bae7b9b2aeec9.tar.gz busybox-w32-c2da68e896d4253466bed202e71bae7b9b2aeec9.tar.bz2 busybox-w32-c2da68e896d4253466bed202e71bae7b9b2aeec9.zip |
bc: optimize bc_parse_pushIndex()
function old new delta
bc_parse_pushIndex 80 68 -12
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 21 |
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) | |||
3460 | 3460 | ||
3461 | static void bc_parse_pushIndex(BcParse *p, size_t idx) | 3461 | static void bc_parse_pushIndex(BcParse *p, size_t idx) |
3462 | { | 3462 | { |
3463 | unsigned char amt, i, nums[sizeof(size_t)]; | 3463 | size_t mask; |
3464 | unsigned amt; | ||
3464 | 3465 | ||
3465 | ///oh boy | 3466 | mask = ((size_t)0xff) << (sizeof(idx) * 8 - 8); |
3466 | for (amt = 0; idx; ++amt) { | 3467 | amt = sizeof(idx); |
3467 | nums[amt] = (char) idx; | 3468 | do { |
3468 | idx = (idx & ((unsigned long) ~(UCHAR_MAX))) >> sizeof(char) * CHAR_BIT; | 3469 | if (idx & mask) break; |
3469 | } | 3470 | mask >>= 8; |
3471 | amt--; | ||
3472 | } while (amt != 0); | ||
3470 | 3473 | ||
3471 | bc_parse_push(p, amt); | 3474 | bc_parse_push(p, amt); |
3472 | for (i = 0; i < amt; ++i) bc_parse_push(p, nums[i]); | 3475 | |
3476 | while (idx != 0) { | ||
3477 | bc_parse_push(p, (unsigned char)idx); | ||
3478 | idx >>= 8; | ||
3479 | } | ||
3473 | } | 3480 | } |
3474 | 3481 | ||
3475 | static void bc_parse_number(BcParse *p, BcInst *prev, size_t *nexs) | 3482 | static void bc_parse_number(BcParse *p, BcInst *prev, size_t *nexs) |