summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2018-12-05 19:00:58 +0100
committerDenys Vlasenko2018-12-05 19:00:58 +0100
commit06fa65bd95455e97d2275ee4d74167f9bfd251c0 (patch)
tree4f9e7f12ecf85bc4abb6be5db18267a970c4a2c2
parentb692c2faf1e713fe4ec04d34bd6ad77e02dbb5d6 (diff)
downloadbusybox-06fa65bd95455e97d2275ee4d74167f9bfd251c0.zip
busybox-06fa65bd95455e97d2275ee4d74167f9bfd251c0.tar.gz
bc: move ^C check fro power calculation to multiplication
function old new delta bc_num_k 971 990 +19 bc_num_p 507 478 -29 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 19/-29) Total: -10 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index ea200eb..07793e9 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -1676,6 +1676,10 @@ static BcStatus bc_num_k(BcNum *restrict a, BcNum *restrict b,
c->num[i + j] += (BcDig) carry;
len = BC_MAX(len, i + j + !!carry);
+
+ // a=2^1000000
+ // a*a <- without check below, this will not be interruptible
+ if (G_interrupt) return BC_STATUS_FAILURE;
}
c->len = len;
@@ -1935,11 +1939,11 @@ static BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
powrdx <<= 1;
s = bc_num_mul(&copy, &copy, &copy, powrdx);
if (s) goto err;
- // It is too slow to handle ^C only after entire "2^1000000" completes
- if (G_interrupt) {
- s = BC_STATUS_FAILURE;
- goto err;
- }
+ // Not needed: bc_num_mul() has a check for ^C:
+ //if (G_interrupt) {
+ // s = BC_STATUS_FAILURE;
+ // goto err;
+ //}
}
bc_num_copy(c, &copy);
@@ -1955,11 +1959,11 @@ static BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
s = bc_num_mul(c, &copy, c, resrdx);
if (s) goto err;
}
- // It is too slow to handle ^C only after entire "2^1000000" completes
- if (G_interrupt) {
- s = BC_STATUS_FAILURE;
- goto err;
- }
+ // Not needed: bc_num_mul() has a check for ^C:
+ //if (G_interrupt) {
+ // s = BC_STATUS_FAILURE;
+ // goto err;
+ //}
}
if (neg) {