Module Name:    src
Committed By:   rillig
Date:           Sat Nov 28 23:32:22 UTC 2020

Modified Files:
        src/usr.bin/make: main.c make.h

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


To generate a diff of this commit:
cvs rdiff -u -r1.483 -r1.484 src/usr.bin/make/main.c
cvs rdiff -u -r1.225 -r1.226 src/usr.bin/make/make.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.483 src/usr.bin/make/main.c:1.484
--- src/usr.bin/make/main.c:1.483	Sat Nov 28 18:55:52 2020
+++ src/usr.bin/make/main.c	Sat Nov 28 23:32:22 2020
@@ -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 @@ MainParseArg(char c, const char *argvalu
 		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 @@ CmdOpts_Init(void)
 	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 @@ ReadFirstDefaultMakefile(void)
 	 * 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 @@ main_ReadFiles(void)
 	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 @@ main_CleanUp(void)
 {
 #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
 

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.225 src/usr.bin/make/make.h:1.226
--- src/usr.bin/make/make.h:1.225	Sat Nov 28 19:22:32 2020
+++ src/usr.bin/make/make.h	Sat Nov 28 23:32:22 2020
@@ -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 @@ typedef struct CmdOpts {
 	Boolean checkEnvFirst;
 
 	/* -f: the makefiles to read */
-	StringList *makefiles;
+	StringList makefiles;
 
 	/* -i: if true, ignore all errors from shell commands */
 	Boolean ignoreErrors;

Reply via email to