diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-22 21:52:30 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-22 21:52:30 +0100 |
| commit | a9f59db809d45847779b9c631d663a25b6115d7d (patch) | |
| tree | 5d1492f5874e9901c38a57270681f35c2c1c854a /miscutils | |
| parent | 2ea8ddf8c245dd160eacf35409572c28345506f7 (diff) | |
| download | busybox-w32-a9f59db809d45847779b9c631d663a25b6115d7d.tar.gz busybox-w32-a9f59db809d45847779b9c631d663a25b6115d7d.tar.bz2 busybox-w32-a9f59db809d45847779b9c631d663a25b6115d7d.zip | |
bc: avoid having to twiddle b->neg in zbc_num_p()
function old new delta
zbc_num_ulong_abs - 70 +70
zbc_num_p 424 413 -11
zbc_num_ulong 81 21 -60
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 70/-71) Total: -1 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/bc.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index d7595ce8e..ae5105b01 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
| @@ -1439,13 +1439,11 @@ static void bc_num_copy(BcNum *d, BcNum *s) | |||
| 1439 | } | 1439 | } |
| 1440 | } | 1440 | } |
| 1441 | 1441 | ||
| 1442 | static BC_STATUS zbc_num_ulong(BcNum *n, unsigned long *result_p) | 1442 | static BC_STATUS zbc_num_ulong_abs(BcNum *n, unsigned long *result_p) |
| 1443 | { | 1443 | { |
| 1444 | size_t i; | 1444 | size_t i; |
| 1445 | unsigned long result; | 1445 | unsigned long result; |
| 1446 | 1446 | ||
| 1447 | if (n->neg) RETURN_STATUS(bc_error("negative number")); | ||
| 1448 | |||
| 1449 | result = 0; | 1447 | result = 0; |
| 1450 | i = n->len; | 1448 | i = n->len; |
| 1451 | while (i > n->rdx) { | 1449 | while (i > n->rdx) { |
| @@ -1462,6 +1460,14 @@ static BC_STATUS zbc_num_ulong(BcNum *n, unsigned long *result_p) | |||
| 1462 | 1460 | ||
| 1463 | RETURN_STATUS(BC_STATUS_SUCCESS); | 1461 | RETURN_STATUS(BC_STATUS_SUCCESS); |
| 1464 | } | 1462 | } |
| 1463 | #define zbc_num_ulong_abs(...) (zbc_num_ulong_abs(__VA_ARGS__) COMMA_SUCCESS) | ||
| 1464 | |||
| 1465 | static BC_STATUS zbc_num_ulong(BcNum *n, unsigned long *result_p) | ||
| 1466 | { | ||
| 1467 | if (n->neg) RETURN_STATUS(bc_error("negative number")); | ||
| 1468 | |||
| 1469 | RETURN_STATUS(zbc_num_ulong_abs(n, result_p)); | ||
| 1470 | } | ||
| 1465 | #define zbc_num_ulong(...) (zbc_num_ulong(__VA_ARGS__) COMMA_SUCCESS) | 1471 | #define zbc_num_ulong(...) (zbc_num_ulong(__VA_ARGS__) COMMA_SUCCESS) |
| 1466 | 1472 | ||
| 1467 | #if ULONG_MAX == 0xffffffffUL // 10 digits: 4294967295 | 1473 | #if ULONG_MAX == 0xffffffffUL // 10 digits: 4294967295 |
| @@ -2109,9 +2115,7 @@ static FAST_FUNC BC_STATUS zbc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size | |||
| 2109 | } | 2115 | } |
| 2110 | 2116 | ||
| 2111 | neg = b->neg; | 2117 | neg = b->neg; |
| 2112 | b->neg = false; | 2118 | s = zbc_num_ulong_abs(b, &pow); |
| 2113 | s = zbc_num_ulong(b, &pow); | ||
| 2114 | b->neg = neg; | ||
| 2115 | if (s) RETURN_STATUS(s); | 2119 | if (s) RETURN_STATUS(s); |
| 2116 | // b is not used beyond this point | 2120 | // b is not used beyond this point |
| 2117 | 2121 | ||
| @@ -6150,7 +6154,6 @@ static BC_STATUS zdc_program_asciify(void) | |||
| 6150 | char *str; | 6154 | char *str; |
| 6151 | char c; | 6155 | char c; |
| 6152 | size_t idx; | 6156 | size_t idx; |
| 6153 | unsigned long val; | ||
| 6154 | 6157 | ||
| 6155 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 0)) | 6158 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 0)) |
| 6156 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 6159 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
| @@ -6160,6 +6163,7 @@ static BC_STATUS zdc_program_asciify(void) | |||
| 6160 | if (s) RETURN_STATUS(s); | 6163 | if (s) RETURN_STATUS(s); |
| 6161 | 6164 | ||
| 6162 | if (BC_PROG_NUM(r, num)) { | 6165 | if (BC_PROG_NUM(r, num)) { |
| 6166 | unsigned long val; | ||
| 6163 | BcNum strmb; | 6167 | BcNum strmb; |
| 6164 | BcDig strmb_digs[ULONG_NUM_BUFSIZE]; | 6168 | BcDig strmb_digs[ULONG_NUM_BUFSIZE]; |
| 6165 | 6169 | ||
