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: in UnexportVars, replace Str_Words with S...



details:   https://anonhg.NetBSD.org/src/rev/33ed41698802
branches:  trunk
changeset: 1026744:33ed41698802
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Dec 05 11:57:18 2021 +0000

description:
make: in UnexportVars, replace Str_Words with Substring_Words

This skips an allocation and a bit of memory copying.

No functional change.

diffstat:

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

diffs (63 lines):

diff -r 1591a15bf7bd -r 33ed41698802 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Dec 05 11:40:03 2021 +0000
+++ b/usr.bin/make/var.c        Sun Dec 05 11:57:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.958 2021/12/03 18:29:35 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.959 2021/12/05 11:57:18 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.958 2021/12/03 18:29:35 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.959 2021/12/05 11:57:18 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -848,15 +848,17 @@
 }
 
 static void
-UnexportVar(const char *varname, UnexportWhat what)
+UnexportVar(Substring varname, UnexportWhat what)
 {
-       Var *v = VarFind(varname, SCOPE_GLOBAL, false);
+       Var *v = VarFindSubstring(varname, SCOPE_GLOBAL, false);
        if (v == NULL) {
-               DEBUG1(VAR, "Not unexporting \"%s\" (not found)\n", varname);
+               DEBUG2(VAR, "Not unexporting \"%.*s\" (not found)\n",
+                   (int)Substring_Length(varname), varname.start);
                return;
        }
 
-       DEBUG1(VAR, "Unexporting \"%s\"\n", varname);
+       DEBUG2(VAR, "Unexporting \"%.*s\"\n",
+           (int)Substring_Length(varname), varname.start);
        if (what != UNEXPORT_ENV && v->exported && !v->reexport)
                unsetenv(v->name.str);
        v->exported = false;
@@ -880,17 +882,15 @@
 UnexportVars(FStr *varnames, UnexportWhat what)
 {
        size_t i;
-       Words words;
+       SubstringWords words;
 
        if (what == UNEXPORT_ENV)
                ClearEnv();
 
-       words = Str_Words(varnames->str, false);
-       for (i = 0; i < words.len; i++) {
-               const char *varname = words.words[i];
-               UnexportVar(varname, what);
-       }
-       Words_Free(words);
+       words = Substring_Words(varnames->str, false);
+       for (i = 0; i < words.len; i++)
+               UnexportVar(words.words[i], what);
+       SubstringWords_Free(words);
 
        if (what != UNEXPORT_NAMED)
                Global_Delete(MAKE_EXPORTED);



Home | Main Index | Thread Index | Old Index