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: save a hash map lookup when defining a cm...



details:   https://anonhg.NetBSD.org/src/rev/a61b186e3b12
branches:  trunk
changeset: 1018972:a61b186e3b12
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Feb 22 21:30:33 2021 +0000

description:
make: save a hash map lookup when defining a cmdline variable

This is a preparation to extract the code for exporting a cmdline
variable.  That code differs in several details from the other code in
ExportVar.

No functional change.

diffstat:

 usr.bin/make/var.c |  16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diffs (70 lines):

diff -r c99b13208964 -r a61b186e3b12 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Mon Feb 22 21:16:25 2021 +0000
+++ b/usr.bin/make/var.c        Mon Feb 22 21:30:33 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.832 2021/02/22 21:14:15 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.833 2021/02/22 21:30:33 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.832 2021/02/22 21:14:15 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.833 2021/02/22 21:30:33 rillig Exp $");
 
 typedef enum VarFlags {
        VFL_NONE        = 0,
@@ -487,7 +487,7 @@
 }
 
 /* Add a new variable of the given name and value to the given scope. */
-static void
+static Var *
 VarAdd(const char *name, const char *value, GNode *scope, VarSetFlags flags)
 {
        HashEntry *he = HashTable_CreateEntry(&scope->vars, name, NULL);
@@ -495,6 +495,7 @@
            flags & VAR_SET_READONLY ? VFL_READONLY : VFL_NONE);
        HashEntry_Set(he, v);
        DEBUG3(VAR, "%s:%s = %s\n", scope->name, name, value);
+       return v;
 }
 
 /*
@@ -980,7 +981,7 @@
                        /* XXX: name is expanded for the second time */
                        Var_DeleteExpand(SCOPE_GLOBAL, name);
                }
-               VarAdd(name, val, scope, flags);
+               v = VarAdd(name, val, scope, flags);
        } else {
                if ((v->flags & VFL_READONLY) && !(flags & VAR_SET_READONLY)) {
                        DEBUG3(VAR, "%s:%s = %s ignored (read-only)\n",
@@ -994,15 +995,13 @@
                if (v->flags & VFL_EXPORTED)
                        ExportVar(name, VEM_PLAIN);
        }
+
        /*
         * Any variables given on the command line are automatically exported
-        * to the environment (as per POSIX standard)
-        * Other than internals.
+        * to the environment (as per POSIX standard), except for internals.
         */
        if (scope == SCOPE_CMDLINE && !(flags & VAR_SET_NO_EXPORT) &&
            name[0] != '.') {
-               if (v == NULL)
-                       v = VarFind(name, scope, FALSE); /* we just added it */
                v->flags |= VFL_FROM_CMD;
 
                /*
@@ -1016,6 +1015,7 @@
 
                Global_Append(MAKEOVERRIDES, name);
        }
+
        if (name[0] == '.' && strcmp(name, MAKE_SAVE_DOLLARS) == 0)
                save_dollars = ParseBoolean(val, save_dollars);
 



Home | Main Index | Thread Index | Old Index