diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-05 19:00:58 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-05 19:00:58 +0100 |
commit | 06fa65bd95455e97d2275ee4d74167f9bfd251c0 (patch) | |
tree | 4f9e7f12ecf85bc4abb6be5db18267a970c4a2c2 /miscutils/bc.c | |
parent | b692c2faf1e713fe4ec04d34bd6ad77e02dbb5d6 (diff) | |
download | busybox-w32-06fa65bd95455e97d2275ee4d74167f9bfd251c0.tar.gz busybox-w32-06fa65bd95455e97d2275ee4d74167f9bfd251c0.tar.bz2 busybox-w32-06fa65bd95455e97d2275ee4d74167f9bfd251c0.zip |
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>
Diffstat (limited to '')
-rw-r--r-- | miscutils/bc.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index ea200ebda..07793e9d4 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -1676,6 +1676,10 @@ static BcStatus bc_num_k(BcNum *restrict a, BcNum *restrict b, | |||
1676 | 1676 | ||
1677 | c->num[i + j] += (BcDig) carry; | 1677 | c->num[i + j] += (BcDig) carry; |
1678 | len = BC_MAX(len, i + j + !!carry); | 1678 | len = BC_MAX(len, i + j + !!carry); |
1679 | |||
1680 | // a=2^1000000 | ||
1681 | // a*a <- without check below, this will not be interruptible | ||
1682 | if (G_interrupt) return BC_STATUS_FAILURE; | ||
1679 | } | 1683 | } |
1680 | 1684 | ||
1681 | c->len = len; | 1685 | c->len = len; |
@@ -1935,11 +1939,11 @@ static BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) | |||
1935 | powrdx <<= 1; | 1939 | powrdx <<= 1; |
1936 | s = bc_num_mul(©, ©, ©, powrdx); | 1940 | s = bc_num_mul(©, ©, ©, powrdx); |
1937 | if (s) goto err; | 1941 | if (s) goto err; |
1938 | // It is too slow to handle ^C only after entire "2^1000000" completes | 1942 | // Not needed: bc_num_mul() has a check for ^C: |
1939 | if (G_interrupt) { | 1943 | //if (G_interrupt) { |
1940 | s = BC_STATUS_FAILURE; | 1944 | // s = BC_STATUS_FAILURE; |
1941 | goto err; | 1945 | // goto err; |
1942 | } | 1946 | //} |
1943 | } | 1947 | } |
1944 | 1948 | ||
1945 | bc_num_copy(c, ©); | 1949 | bc_num_copy(c, ©); |
@@ -1955,11 +1959,11 @@ static BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) | |||
1955 | s = bc_num_mul(c, ©, c, resrdx); | 1959 | s = bc_num_mul(c, ©, c, resrdx); |
1956 | if (s) goto err; | 1960 | if (s) goto err; |
1957 | } | 1961 | } |
1958 | // It is too slow to handle ^C only after entire "2^1000000" completes | 1962 | // Not needed: bc_num_mul() has a check for ^C: |
1959 | if (G_interrupt) { | 1963 | //if (G_interrupt) { |
1960 | s = BC_STATUS_FAILURE; | 1964 | // s = BC_STATUS_FAILURE; |
1961 | goto err; | 1965 | // goto err; |
1962 | } | 1966 | //} |
1963 | } | 1967 | } |
1964 | 1968 | ||
1965 | if (neg) { | 1969 | if (neg) { |