diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-10 15:38:52 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-10 15:38:52 +0100 |
commit | dafbc2cdb8825ed36a25f9a6275d5226f35d3bd3 (patch) | |
tree | 9f9535fb5d0fa988ca33595a593b99bb95ac8694 /miscutils/bc.c | |
parent | 5ba55f1f356f3521d2b366d6d7af60c5e05563a8 (diff) |
bc: simplify bc_num_parseDecimal() further
function old new delta
bc_program_num 925 912 -13
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils/bc.c')
-rw-r--r-- | miscutils/bc.c | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 7ed6dd91d..26ab94cbd 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c @@ -2395,19 +2395,11 @@ static void bc_num_parseDecimal(BcNum *n, const char *val) { size_t len, i; const char *ptr; - bool zero; len = strlen(val); if (len == 0) return; - zero = true; - for (i = 0; val[i]; ++i) { - if (val[i] != '0' && val[i] != '.') { - zero = false; - break; - } - } bc_num_expand(n, len); ptr = strchr(val, '.'); @@ -2416,16 +2408,21 @@ static void bc_num_parseDecimal(BcNum *n, const char *val) if (ptr != NULL) n->rdx = (size_t)((val + len) - (ptr + 1)); - if (!zero) { - i = len - 1; - for (;;) { - n->num[n->len] = val[i] - '0'; - ++n->len; + for (i = 0; val[i]; ++i) { + if (val[i] != '0' && val[i] != '.') { + // Not entirely zero value - convert it, and exit + i = len - 1; + for (;;) { + n->num[n->len] = val[i] - '0'; + ++n->len; skip_dot: - if ((ssize_t)--i == (ssize_t)-1) break; - if (val[i] == '.') goto skip_dot; + if ((ssize_t)--i == (ssize_t)-1) break; + if (val[i] == '.') goto skip_dot; + } + break; } } + // if this is reached, the value is entirely zero } // Note: n is already "bc_num_zero()"ed, |