bc: further simplify string-to-number conversion code
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 9 Dec 2018 12:33:52 +0000 (13:33 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 9 Dec 2018 12:33:52 +0000 (13:33 +0100)
function                                             old     new   delta
bc_program_index                                      66      64      -2
bc_program_num                                       983     963     -20
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-22)             Total: -22 bytes
   text    data     bss     dec     hex filename
 985706     477    7296  993479   f28c7 busybox_old
 985684     477    7296  993457   f28b1 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
miscutils/bc.c

index c36486414257596afd8883f6c165644fa01ed192..ca9506929d6cd676265a5681bb8964f80253d353 100644 (file)
@@ -2246,8 +2246,14 @@ static void bc_num_parseDecimal(BcNum *n, const char *val)
                n->rdx = (size_t)((val + len) - (ptr + 1));
 
        if (!zero) {
-               for (i = len - 1; i < len; ++n->len, i -= 1 + (i && val[i - 1] == '.'))
+               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;
+               }
        }
 }