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(1): reduce memory allocation in CmdOpts.ma...



details:   https://anonhg.NetBSD.org/src/rev/8372b22c5c21
branches:  trunk
changeset: 957450:8372b22c5c21
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Nov 28 23:32:22 2020 +0000

description:
make(1): reduce memory allocation in CmdOpts.makefiles

diffstat:

 usr.bin/make/main.c |  22 +++++++++++++---------
 usr.bin/make/make.h |   4 ++--
 2 files changed, 15 insertions(+), 11 deletions(-)

diffs (90 lines):

diff -r 6c4dcb7c5b6d -r 8372b22c5c21 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Sat Nov 28 23:22:14 2020 +0000
+++ b/usr.bin/make/main.c       Sat Nov 28 23:32:22 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.483 2020/11/28 18:55:52 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.484 2020/11/28 23:32:22 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "trace.h"
 
 /*     "@(#)main.c     8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.483 2020/11/28 18:55:52 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.484 2020/11/28 23:32:22 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
            "The Regents of the University of California.  "
@@ -528,7 +528,7 @@
                Var_Append(MAKEFLAGS, "-e", VAR_GLOBAL);
                break;
        case 'f':
-               Lst_Append(opts.makefiles, bmake_strdup(argvalue));
+               Lst_Append(&opts.makefiles, bmake_strdup(argvalue));
                break;
        case 'i':
                opts.ignoreErrors = TRUE;
@@ -1126,7 +1126,7 @@
        opts.lint = FALSE;
        opts.debugVflag = FALSE;
        opts.checkEnvFirst = FALSE;
-       opts.makefiles = Lst_New();
+       Lst_Init(&opts.makefiles);
        opts.ignoreErrors = FALSE;      /* Pay attention to non-zero returns */
        opts.maxJobs = DEFMAXLOCAL;     /* Set default local max concurrency */
        opts.keepgoing = FALSE;         /* Stop on error */
@@ -1321,9 +1321,9 @@
         * since these makefiles do not come from the command line.  They
         * also have different semantics in that only the first file that
         * is found is processed.  See ReadAllMakefiles. */
-       (void)str2Lst_Append(opts.makefiles, prefs);
+       (void)str2Lst_Append(&opts.makefiles, prefs);
 
-       for (ln = opts.makefiles->first; ln != NULL; ln = ln->next)
+       for (ln = opts.makefiles.first; ln != NULL; ln = ln->next)
                if (ReadMakefile(ln->datum) == 0)
                        break;
 
@@ -1531,8 +1531,8 @@
        if (!opts.noBuiltins)
                ReadBuiltinRules();
 
-       if (!Lst_IsEmpty(opts.makefiles))
-               ReadAllMakefiles(opts.makefiles);
+       if (!Lst_IsEmpty(&opts.makefiles))
+               ReadAllMakefiles(&opts.makefiles);
        else
                ReadFirstDefaultMakefile();
 }
@@ -1622,7 +1622,11 @@
 {
 #ifdef CLEANUP
        Lst_Destroy(opts.variables, free);
-       Lst_Free(opts.makefiles);       /* don't free, may be used in GNodes */
+       /*
+        * Don't free the actual strings from opts.makefiles, they may be
+        * used in GNodes.
+        */
+       Lst_Done(&opts.makefiles);
        Lst_Destroy(opts.create, free);
 #endif
 
diff -r 6c4dcb7c5b6d -r 8372b22c5c21 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Sat Nov 28 23:22:14 2020 +0000
+++ b/usr.bin/make/make.h       Sat Nov 28 23:32:22 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.225 2020/11/28 19:22:32 rillig Exp $        */
+/*     $NetBSD: make.h,v 1.226 2020/11/28 23:32:22 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -635,7 +635,7 @@
        Boolean checkEnvFirst;
 
        /* -f: the makefiles to read */
-       StringList *makefiles;
+       StringList makefiles;
 
        /* -i: if true, ignore all errors from shell commands */
        Boolean ignoreErrors;



Home | Main Index | Thread Index | Old Index