Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): don't needlessly chain p-- and p++ in ...



details:   https://anonhg.NetBSD.org/src/rev/9afac9d7c9da
branches:  trunk
changeset: 936717:9afac9d7c9da
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 02 10:01:50 2020 +0000

description:
make(1): don't needlessly chain p-- and p++ in ParseModifierPart

At least GCC 5 didn't optimize this, although I wouldn't have been
surprised if it did.

diffstat:

 usr.bin/make/var.c |  21 ++++++++++++---------
 1 files changed, 12 insertions(+), 9 deletions(-)

diffs (82 lines):

diff -r bbcde1b8fcd9 -r 9afac9d7c9da usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Aug 02 09:54:44 2020 +0000
+++ b/usr.bin/make/var.c        Sun Aug 02 10:01:50 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.393 2020/08/02 09:54:44 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.394 2020/08/02 10:01:50 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.393 2020/08/02 09:54:44 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.394 2020/08/02 10:01:50 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c      8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.393 2020/08/02 09:54:44 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.394 2020/08/02 10:01:50 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1758,14 +1758,14 @@
      * backslashes to quote the delimiter, $, and \, but don't
      * touch other backslashes.
      */
-    const char *p;
-    for (p = *pp; *p != '\0' && *p != delim; p++) {
+    const char *p = *pp;
+    while (*p != '\0' && *p != delim) {
        Boolean is_escaped = p[0] == '\\' && (
            p[1] == delim || p[1] == '\\' || p[1] == '$' ||
            (p[1] == '&' && subst != NULL));
        if (is_escaped) {
            Buf_AddByte(&buf, p[1]);
-           p++;
+           p += 2;
            continue;
        }
 
@@ -1774,6 +1774,7 @@
                Buf_AddBytesZ(&buf, subst->lhs, subst->lhsLen);
            else
                Buf_AddByte(&buf, *p);
+           p++;
            continue;
        }
 
@@ -1782,6 +1783,7 @@
                *out_pflags |= VARP_ANCHOR_END;
            else
                Buf_AddByte(&buf, *p);
+           p++;
            continue;
        }
 
@@ -1794,7 +1796,7 @@
                            &len, &freeIt);
            Buf_AddStr(&buf, cp2);
            free(freeIt);
-           p += len - 1;
+           p += len;
            continue;
        }
 
@@ -1818,9 +1820,10 @@
                }
            }
            Buf_AddBytesBetween(&buf, varstart, p);
-           p--;
-       } else
+       } else {
            Buf_AddByte(&buf, *varstart);
+           p++;
+       }
     }
 
     if (*p != delim) {



Home | Main Index | Thread Index | Old Index