Fri Oct 30 07:47:11 2020 UTC ()
make(1): remove redundant evaluations in VarFind


(rillig)
diff -r1.596 -r1.597 src/usr.bin/make/var.c

cvs diff -r1.596 -r1.597 src/usr.bin/make/var.c (expand / switch to unified diff)

--- src/usr.bin/make/var.c 2020/10/30 07:37:30 1.596
+++ src/usr.bin/make/var.c 2020/10/30 07:47:11 1.597
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: var.c,v 1.596 2020/10/30 07:37:30 rillig Exp $ */ 1/* $NetBSD: var.c,v 1.597 2020/10/30 07:47:11 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -119,27 +119,27 @@ @@ -119,27 +119,27 @@
119#include <sys/types.h> 119#include <sys/types.h>
120#include <regex.h> 120#include <regex.h>
121#endif 121#endif
122#include <inttypes.h> 122#include <inttypes.h>
123#include <limits.h> 123#include <limits.h>
124#include <time.h> 124#include <time.h>
125 125
126#include "make.h" 126#include "make.h"
127#include "dir.h" 127#include "dir.h"
128#include "job.h" 128#include "job.h"
129#include "metachar.h" 129#include "metachar.h"
130 130
131/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ 131/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
132MAKE_RCSID("$NetBSD: var.c,v 1.596 2020/10/30 07:37:30 rillig Exp $"); 132MAKE_RCSID("$NetBSD: var.c,v 1.597 2020/10/30 07:47:11 rillig Exp $");
133 133
134#define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1) 134#define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
135#define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2) 135#define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
136#define VAR_DEBUG3(fmt, arg1, arg2, arg3) DEBUG3(VAR, fmt, arg1, arg2, arg3) 136#define VAR_DEBUG3(fmt, arg1, arg2, arg3) DEBUG3(VAR, fmt, arg1, arg2, arg3)
137#define VAR_DEBUG4(fmt, arg1, arg2, arg3, arg4) DEBUG4(VAR, fmt, arg1, arg2, arg3, arg4) 137#define VAR_DEBUG4(fmt, arg1, arg2, arg3, arg4) DEBUG4(VAR, fmt, arg1, arg2, arg3, arg4)
138 138
139ENUM_FLAGS_RTTI_3(VarEvalFlags, 139ENUM_FLAGS_RTTI_3(VarEvalFlags,
140 VARE_UNDEFERR, VARE_WANTRES, VARE_ASSIGN); 140 VARE_UNDEFERR, VARE_WANTRES, VARE_ASSIGN);
141 141
142/* 142/*
143 * This lets us tell if we have replaced the original environ 143 * This lets us tell if we have replaced the original environ
144 * (which we cannot free). 144 * (which we cannot free).
145 */ 145 */
@@ -367,47 +367,49 @@ VarFind(const char *name, GNode *ctxt, B @@ -367,47 +367,49 @@ VarFind(const char *name, GNode *ctxt, B
367 * the local ones. We check the name against all the local variables 367 * the local ones. We check the name against all the local variables
368 * and substitute the short version in for 'name' if it matches one of 368 * and substitute the short version in for 'name' if it matches one of
369 * them. 369 * them.
370 */ 370 */
371 name = CanonicalVarname(name); 371 name = CanonicalVarname(name);
372 nameHash = Hash_Hash(name); 372 nameHash = Hash_Hash(name);
373 373
374 /* 374 /*
375 * First look for the variable in the given context. If it's not there, 375 * First look for the variable in the given context. If it's not there,
376 * look for it in VAR_CMDLINE, VAR_GLOBAL and the environment, in that order, 376 * look for it in VAR_CMDLINE, VAR_GLOBAL and the environment, in that order,
377 * depending on the FIND_* flags in 'flags' 377 * depending on the FIND_* flags in 'flags'
378 */ 378 */
379 var = GNode_FindVar(ctxt, name, nameHash); 379 var = GNode_FindVar(ctxt, name, nameHash);
 380 if (!elsewhere)
 381 return var;
380 382
381 if (var == NULL && elsewhere && ctxt != VAR_CMDLINE) 383 if (var == NULL && ctxt != VAR_CMDLINE)
382 var = GNode_FindVar(VAR_CMDLINE, name, nameHash); 384 var = GNode_FindVar(VAR_CMDLINE, name, nameHash);
383 385
384 if (!opts.checkEnvFirst && var == NULL && elsewhere && ctxt != VAR_GLOBAL) { 386 if (!opts.checkEnvFirst && var == NULL && ctxt != VAR_GLOBAL) {
385 var = GNode_FindVar(VAR_GLOBAL, name, nameHash); 387 var = GNode_FindVar(VAR_GLOBAL, name, nameHash);
386 if (var == NULL && ctxt != VAR_INTERNAL) { 388 if (var == NULL && ctxt != VAR_INTERNAL) {
387 /* VAR_INTERNAL is subordinate to VAR_GLOBAL */ 389 /* VAR_INTERNAL is subordinate to VAR_GLOBAL */
388 var = GNode_FindVar(VAR_INTERNAL, name, nameHash); 390 var = GNode_FindVar(VAR_INTERNAL, name, nameHash);
389 } 391 }
390 } 392 }
391 393
392 if (var == NULL && elsewhere) { 394 if (var == NULL) {
393 char *env; 395 char *env;
394 396
395 if ((env = getenv(name)) != NULL) { 397 if ((env = getenv(name)) != NULL) {
396 char *varname = bmake_strdup(name); 398 char *varname = bmake_strdup(name);
397 return VarNew(varname, varname, env, VAR_FROM_ENV); 399 return VarNew(varname, varname, env, VAR_FROM_ENV);
398 } 400 }
399 401
400 if (opts.checkEnvFirst && elsewhere && ctxt != VAR_GLOBAL) { 402 if (opts.checkEnvFirst && ctxt != VAR_GLOBAL) {
401 var = GNode_FindVar(VAR_GLOBAL, name, nameHash); 403 var = GNode_FindVar(VAR_GLOBAL, name, nameHash);
402 if (var == NULL && ctxt != VAR_INTERNAL) 404 if (var == NULL && ctxt != VAR_INTERNAL)
403 var = GNode_FindVar(VAR_INTERNAL, name, nameHash); 405 var = GNode_FindVar(VAR_INTERNAL, name, nameHash);
404 return var; 406 return var;
405 } 407 }
406 408
407 return NULL; 409 return NULL;
408 } 410 }
409 411
410 return var; 412 return var;
411} 413}
412 414
413/*- 415/*-