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: restructure code in ParseVarname to targe...
details: https://anonhg.NetBSD.org/src/rev/7a8a29247c14
branches: trunk
changeset: 953022:7a8a29247c14
user: rillig <rillig%NetBSD.org@localhost>
date: Tue Feb 23 16:14:11 2021 +0000
description:
make: restructure code in ParseVarname to target human readers
Breaking the loop once for depth == 0 and once for depth == 1 was
unnecessarily confusing, as was the nested 'if'. Start counting with 0
since there is no reason to start at 1.
Evaluating the common subexpression '*p == endc' is left as an exercise
to the compiler.
No functional change.
diffstat:
usr.bin/make/var.c | 17 +++++++----------
1 files changed, 7 insertions(+), 10 deletions(-)
diffs (44 lines):
diff -r f6bd1bbb62ab -r 7a8a29247c14 usr.bin/make/var.c
--- a/usr.bin/make/var.c Tue Feb 23 16:07:14 2021 +0000
+++ b/usr.bin/make/var.c Tue Feb 23 16:14:11 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.853 2021/02/23 16:07:14 rillig Exp $ */
+/* $NetBSD: var.c,v 1.854 2021/02/23 16:14:11 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.853 2021/02/23 16:07:14 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.854 2021/02/23 16:14:11 rillig Exp $");
typedef enum VarFlags {
VFL_NONE = 0,
@@ -3900,20 +3900,17 @@
{
Buffer buf;
const char *p = *pp;
- int depth = 1;
+ int depth = 0; /* Track depth so we can spot parse errors. */
Buf_Init(&buf);
while (*p != '\0') {
- /* Track depth so we can spot parse errors. */
+ if ((*p == endc || *p == ':') && depth == 0)
+ break;
if (*p == startc)
depth++;
- if (*p == endc) {
- if (--depth == 0)
- break;
- }
- if (*p == ':' && depth == 1)
- break;
+ if (*p == endc)
+ depth--;
/* A variable inside a variable, expand. */
if (*p == '$') {
Home |
Main Index |
Thread Index |
Old Index