Module Name: src Committed By: rillig Date: Tue Feb 23 16:14:11 UTC 2021
Modified Files: src/usr.bin/make: var.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.853 -r1.854 src/usr.bin/make/var.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/var.c diff -u src/usr.bin/make/var.c:1.853 src/usr.bin/make/var.c:1.854 --- src/usr.bin/make/var.c:1.853 Tue Feb 23 16:07:14 2021 +++ src/usr.bin/make/var.c Tue Feb 23 16:14:11 2021 @@ -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 @@ ParseVarname(const char **pp, char start { 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 == '$') {