bc: optimize zbc_lex_string()
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 18 Dec 2018 13:03:20 +0000 (14:03 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 18 Dec 2018 13:03:20 +0000 (14:03 +0100)
function                                             old     new   delta
zbc_lex_next                                        2359    2353      -6

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

index 5d969c9d0ef1101743618c55b03b719495f34ec7..be198a5fbd8ec19fe6304b844613c7bacda5b25d 100644 (file)
@@ -2986,17 +2986,22 @@ static BC_STATUS zbc_lex_identifier(BcLex *l)
 
 static BC_STATUS zbc_lex_string(BcLex *l)
 {
-       size_t len, nls = 0, i = l->i;
-       char c;
+       size_t len, nls, i;
 
        l->t.t = BC_LEX_STR;
 
-       for (c = l->buf[i]; c != '\0' && c != '"'; c = l->buf[++i])
+       nls = 0;
+       i = l->i;
+       for (;;) {
+               char c = l->buf[i];
+               if (c == '\0') {
+                       l->i = i;
+                       RETURN_STATUS(bc_error("string end could not be found"));
+               }
+               if (c == '"')
+                       break;
                nls += (c == '\n');
-
-       if (c == '\0') {
-               l->i = i;
-               RETURN_STATUS(bc_error("string end could not be found"));
+               i++;
        }
 
        len = i - l->i;