diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-26 20:30:47 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-26 20:30:47 +0100 |
commit | ab9a98602f9a0c37f9382a57e421fe4e058d4a67 (patch) | |
tree | 21fcaef7ec4246480bd6712bf66507ec96e089ae /miscutils | |
parent | f706a18f33a5e6360cd7567c6c5fc9714be3ed39 (diff) | |
download | busybox-w32-ab9a98602f9a0c37f9382a57e421fe4e058d4a67.tar.gz busybox-w32-ab9a98602f9a0c37f9382a57e421fe4e058d4a67.tar.bz2 busybox-w32-ab9a98602f9a0c37f9382a57e421fe4e058d4a67.zip |
bc: simple speedups
function old new delta
bc_parse_pushName 20 56 +36
bc_program_index 47 71 +24
bc_parse_pushIndex 52 58 +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 66/0) Total: 66 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/bc.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 2569967d6..cf04e9ff1 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -3439,17 +3439,38 @@ static void bc_parse_push(char i) | |||
3439 | 3439 | ||
3440 | static void bc_parse_pushName(char *name) | 3440 | static void bc_parse_pushName(char *name) |
3441 | { | 3441 | { |
3442 | #if 1 | ||
3443 | BcVec *code = &G.prs.func->code; | ||
3444 | size_t pos = code->len; | ||
3445 | size_t len = strlen(name) + 1; | ||
3446 | |||
3447 | bc_vec_expand(code, pos + len); | ||
3448 | strcpy(code->v + pos, name); | ||
3449 | code->len = pos + len; | ||
3450 | #else | ||
3451 | // Smaller code, but way slow: | ||
3442 | do { | 3452 | do { |
3443 | bc_parse_push(*name); | 3453 | bc_parse_push(*name); |
3444 | } while (*name++); | 3454 | } while (*name++); |
3455 | #endif | ||
3445 | } | 3456 | } |
3446 | 3457 | ||
3458 | // Indexes < 0xfc are encoded verbatim, else first byte is | ||
3459 | // 0xfc, 0xfd, 0xfe or 0xff, encoding "1..4 bytes", | ||
3460 | // followed by that many bytes, lsb first. | ||
3461 | // (The above describes 32-bit case). | ||
3462 | #define SMALL_INDEX_LIMIT (0x100 - sizeof(size_t)) | ||
3463 | |||
3447 | static void bc_parse_pushIndex(size_t idx) | 3464 | static void bc_parse_pushIndex(size_t idx) |
3448 | { | 3465 | { |
3449 | size_t mask; | 3466 | size_t mask; |
3450 | unsigned amt; | 3467 | unsigned amt; |
3451 | 3468 | ||
3452 | dbg_lex("%s:%d pushing index %zd", __func__, __LINE__, idx); | 3469 | dbg_lex("%s:%d pushing index %zd", __func__, __LINE__, idx); |
3470 | if (idx < SMALL_INDEX_LIMIT) { | ||
3471 | goto push_idx; | ||
3472 | } | ||
3473 | |||
3453 | mask = ((size_t)0xff) << (sizeof(idx) * 8 - 8); | 3474 | mask = ((size_t)0xff) << (sizeof(idx) * 8 - 8); |
3454 | amt = sizeof(idx); | 3475 | amt = sizeof(idx); |
3455 | do { | 3476 | do { |
@@ -3458,9 +3479,10 @@ static void bc_parse_pushIndex(size_t idx) | |||
3458 | amt--; | 3479 | amt--; |
3459 | } while (amt != 0); | 3480 | } while (amt != 0); |
3460 | 3481 | ||
3461 | bc_parse_push(amt); | 3482 | bc_parse_push(SMALL_INDEX_LIMIT + amt); |
3462 | 3483 | ||
3463 | while (idx != 0) { | 3484 | while (idx != 0) { |
3485 | push_idx: | ||
3464 | bc_parse_push((unsigned char)idx); | 3486 | bc_parse_push((unsigned char)idx); |
3465 | idx >>= 8; | 3487 | idx >>= 8; |
3466 | } | 3488 | } |
@@ -5257,6 +5279,11 @@ static size_t bc_program_index(char *code, size_t *bgn) | |||
5257 | size_t res; | 5279 | size_t res; |
5258 | 5280 | ||
5259 | amt = *bytes++; | 5281 | amt = *bytes++; |
5282 | if (amt < SMALL_INDEX_LIMIT) { | ||
5283 | *bgn += 1; | ||
5284 | return amt; | ||
5285 | } | ||
5286 | amt -= SMALL_INDEX_LIMIT; | ||
5260 | *bgn += amt + 1; | 5287 | *bgn += amt + 1; |
5261 | 5288 | ||
5262 | amt *= 8; | 5289 | amt *= 8; |