Module Name: src
Committed By: rillig
Date: Thu Sep 2 06:29:56 UTC 2021
Modified Files:
src/usr.bin/make: for.c
Log Message:
make: inline strchr call, make ForLoop_SubstBody clearer
In ForLoop_SubstBody, GCC already merged the common subexpressions p[1]
and p[-1], but that was difficult to see for humans as well.
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 src/usr.bin/make/for.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/for.c
diff -u src/usr.bin/make/for.c:1.145 src/usr.bin/make/for.c:1.146
--- src/usr.bin/make/for.c:1.145 Wed Sep 1 23:07:41 2021
+++ src/usr.bin/make/for.c Thu Sep 2 06:29:56 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: for.c,v 1.145 2021/09/01 23:07:41 rillig Exp $ */
+/* $NetBSD: for.c,v 1.146 2021/09/02 06:29:56 rillig Exp $ */
/*
* Copyright (c) 1992, The Regents of the University of California.
@@ -58,7 +58,7 @@
#include "make.h"
/* "@(#)for.c 8.1 (Berkeley) 6/6/93" */
-MAKE_RCSID("$NetBSD: for.c,v 1.145 2021/09/01 23:07:41 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.146 2021/09/02 06:29:56 rillig Exp $");
/* One of the variables to the left of the "in" in a .for loop. */
@@ -363,7 +363,7 @@ Buf_AddEscaped(Buffer *cmds, const char
}
/*
- * While expanding the body of a .for loop, replace the variable name of an
+ * When expanding the body of a .for loop, replace the variable name of an
* expression like ${i} or ${i:...} or $(i) or $(i:...) with ":Uvalue".
*/
static void
@@ -404,7 +404,7 @@ ForLoop_SubstVarLong(ForLoop *f, const c
}
/*
- * While expanding the body of a .for loop, replace single-character
+ * When expanding the body of a .for loop, replace single-character
* variable expressions like $i with their ${:U...} expansion.
*/
static void
@@ -415,7 +415,7 @@ ForLoop_SubstVarShort(ForLoop *f, const
size_t i;
/* Skip $$ and stupid ones. */
- if (strchr("}):$", ch) != NULL)
+ if (ch == '}' || ch == ')' || ch == ':' || ch == '$')
return;
vars = Vector_Get(&f->vars, 0);
@@ -451,7 +451,7 @@ static void
ForLoop_SubstBody(ForLoop *f)
{
const char *p, *bodyEnd;
- const char *mark; /* where the last replacement left off */
+ const char *mark; /* where the last substitution left off */
Buf_Empty(&f->curBody);
@@ -459,9 +459,9 @@ ForLoop_SubstBody(ForLoop *f)
bodyEnd = f->body.data + f->body.len;
for (p = mark; (p = strchr(p, '$')) != NULL;) {
if (p[1] == '{' || p[1] == '(') {
+ char endc = p[1] == '{' ? '}' : ')';
p += 2;
- ForLoop_SubstVarLong(f, &p, bodyEnd,
- p[-1] == '{' ? '}' : ')', &mark);
+ ForLoop_SubstVarLong(f, &p, bodyEnd, endc, &mark);
} else if (p[1] != '\0') {
ForLoop_SubstVarShort(f, p + 1, &mark);
p += 2;