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: split Var_Exists into plain Var_Exists an...



details:   https://anonhg.NetBSD.org/src/rev/0d7056cda3f4
branches:  trunk
changeset: 1018439:0d7056cda3f4
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Feb 03 14:33:09 2021 +0000

description:
make: split Var_Exists into plain Var_Exists and Var_ExistsExpand

Most previous calls to Var_Exists use constant variable names.  Only the
two calls in parse.c need to expand the variable name.

It may be a good idea to expand the variable name once in VarAssign_Eval
instead of repeating the expansion in each of its special cases.

No functional change.

diffstat:

 usr.bin/make/nonints.h |   3 ++-
 usr.bin/make/parse.c   |   8 ++++----
 usr.bin/make/var.c     |  31 ++++++++++++++++++++-----------
 3 files changed, 26 insertions(+), 16 deletions(-)

diffs (129 lines):

diff -r 6a7d0c693e15 -r 0d7056cda3f4 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Wed Feb 03 14:22:21 2021 +0000
+++ b/usr.bin/make/nonints.h    Wed Feb 03 14:33:09 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.194 2021/02/03 13:53:12 rillig Exp $     */
+/*     $NetBSD: nonints.h,v 1.195 2021/02/03 14:33:09 rillig Exp $     */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -379,6 +379,7 @@
 void Var_AppendExpand(const char *, const char *, GNode *);
 void Global_Append(const char *, const char *);
 Boolean Var_Exists(const char *, GNode *);
+Boolean Var_ExistsExpand(const char *, GNode *);
 FStr Var_Value(const char *, GNode *);
 const char *Var_ValueDirect(const char *, GNode *);
 VarParseResult Var_Parse(const char **, GNode *, VarEvalFlags, FStr *);
diff -r 6a7d0c693e15 -r 0d7056cda3f4 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Wed Feb 03 14:22:21 2021 +0000
+++ b/usr.bin/make/parse.c      Wed Feb 03 14:33:09 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.542 2021/02/03 13:53:12 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.543 2021/02/03 14:33:09 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.542 2021/02/03 13:53:12 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.543 2021/02/03 14:33:09 rillig Exp $");
 
 /* types and constants */
 
@@ -1897,7 +1897,7 @@
         * TODO: Add a test that demonstrates why this code is needed,
         *  apart from making the debug log longer.
         */
-       if (!Var_Exists(name, ctxt))
+       if (!Var_ExistsExpand(name, ctxt))
                Var_Set(name, "", ctxt);
 
        (void)Var_Subst(uvalue, ctxt,
@@ -1960,7 +1960,7 @@
        else if (op == VAR_SHELL)
                VarAssign_EvalShell(name, uvalue, ctxt, &avalue);
        else {
-               if (op == VAR_DEFAULT && Var_Exists(name, ctxt))
+               if (op == VAR_DEFAULT && Var_ExistsExpand(name, ctxt))
                        return FALSE;
 
                /* Normal assignment -- just do it. */
diff -r 6a7d0c693e15 -r 0d7056cda3f4 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Wed Feb 03 14:22:21 2021 +0000
+++ b/usr.bin/make/var.c        Wed Feb 03 14:33:09 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.795 2021/02/03 13:53:12 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.796 2021/02/03 14:33:09 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -89,7 +89,9 @@
  *                     necessary. A space is placed between the old value and
  *                     the new one.
  *
- *     Var_Exists      See if a variable exists.
+ *     Var_Exists
+ *     Var_ExistsExpand
+ *                     See if a variable exists.
  *
  *     Var_Value       Return the unexpanded value of a variable, or NULL if
  *                     the variable is undefined.
@@ -133,7 +135,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.795 2021/02/03 13:53:12 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.796 2021/02/03 14:33:09 rillig Exp $");
 
 typedef enum VarFlags {
        VAR_NONE        = 0,
@@ -1146,6 +1148,17 @@
        Var_Append(name, value, VAR_GLOBAL);
 }
 
+Boolean
+Var_Exists(const char *name, GNode *ctxt)
+{
+       Var *v = VarFind(name, ctxt, TRUE);
+       if (v == NULL)
+               return FALSE;
+
+       (void)VarFreeEnv(v, TRUE);
+       return TRUE;
+}
+
 /*
  * See if the given variable exists, in the given context or in other
  * fallback contexts.
@@ -1155,10 +1168,10 @@
  *     ctxt            Context in which to start search
  */
 Boolean
-Var_Exists(const char *name, GNode *ctxt)
+Var_ExistsExpand(const char *name, GNode *ctxt)
 {
        FStr varname = FStr_InitRefer(name);
-       Var *v;
+       Boolean exists;
 
        if (strchr(varname.str, '$') != NULL) {
                char *expanded;
@@ -1167,13 +1180,9 @@
                varname = FStr_InitOwn(expanded);
        }
 
-       v = VarFind(varname.str, ctxt, TRUE);
+       exists = Var_Exists(varname.str, ctxt);
        FStr_Done(&varname);
-       if (v == NULL)
-               return FALSE;
-
-       (void)VarFreeEnv(v, TRUE);
-       return TRUE;
+       return exists;
 }
 
 /*



Home | Main Index | Thread Index | Old Index