Module Name:    src
Committed By:   rillig
Date:           Sun Nov 29 00:04:23 UTC 2020

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

Log Message:
make(1): reduce memory allocation for targets

This change moves the initialization and finalization of the list of
targets to the same function.  They had been split before.


To generate a diff of this commit:
cvs rdiff -u -r1.487 -r1.488 src/usr.bin/make/main.c
cvs rdiff -u -r1.163 -r1.164 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.460 -r1.461 src/usr.bin/make/parse.c
cvs rdiff -u -r1.146 -r1.147 src/usr.bin/make/targ.c

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.487 src/usr.bin/make/main.c:1.488
--- src/usr.bin/make/main.c:1.487	Sat Nov 28 23:43:14 2020
+++ src/usr.bin/make/main.c	Sun Nov 29 00:04:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.487 2020/11/28 23:43:14 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.488 2020/11/29 00:04: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.487 2020/11/28 23:43:14 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.488 2020/11/29 00:04:22 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	    "The Regents of the University of California.  "
@@ -913,7 +913,7 @@ doPrintVars(void)
 static Boolean
 runTargets(void)
 {
-	GNodeList *targs;	/* target nodes to create */
+	GNodeList targs = LST_INIT;	/* target nodes to create */
 	Boolean outOfDate;	/* FALSE if all targets up to date */
 
 	/*
@@ -923,9 +923,9 @@ runTargets(void)
 	 * to create.
 	 */
 	if (Lst_IsEmpty(&opts.create))
-		targs = Parse_MainName();
+		Parse_MainName(&targs);
 	else
-		targs = Targ_FindList(&opts.create);
+		Targ_FindList(&targs, &opts.create);
 
 	if (!opts.compatMake) {
 		/*
@@ -941,16 +941,16 @@ runTargets(void)
 		}
 
 		/* Traverse the graph, checking on all the targets */
-		outOfDate = Make_Run(targs);
+		outOfDate = Make_Run(&targs);
 	} else {
 		/*
 		 * Compat_Init will take care of creating all the
 		 * targets as well as initializing the module.
 		 */
-		Compat_Run(targs);
+		Compat_Run(&targs);
 		outOfDate = FALSE;
 	}
-	Lst_Free(targs);
+	Lst_Done(&targs);	/* Don't free the nodes. */
 	return outOfDate;
 }
 

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.163 src/usr.bin/make/nonints.h:1.164
--- src/usr.bin/make/nonints.h:1.163	Sat Nov 28 22:56:01 2020
+++ src/usr.bin/make/nonints.h	Sun Nov 29 00:04:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.163 2020/11/28 22:56:01 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.164 2020/11/29 00:04:22 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -153,7 +153,7 @@ void Parse_DoVar(VarAssign *, GNode *);
 void Parse_AddIncludeDir(const char *);
 void Parse_File(const char *, int);
 void Parse_SetInput(const char *, int, int, NextBufProc, void *);
-GNodeList *Parse_MainName(void);
+void Parse_MainName(GNodeList *);
 int Parse_GetFatals(void);
 
 /* str.c */
@@ -204,7 +204,7 @@ GNode *Targ_FindNode(const char *);
 GNode *Targ_GetNode(const char *);
 GNode *Targ_NewInternalNode(const char *);
 GNode *Targ_GetEndNode(void);
-GNodeList *Targ_FindList(StringList *);
+void Targ_FindList(GNodeList *, StringList *);
 Boolean Targ_Ignore(const GNode *);
 Boolean Targ_Silent(const GNode *);
 Boolean Targ_Precious(const GNode *);

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.460 src/usr.bin/make/parse.c:1.461
--- src/usr.bin/make/parse.c:1.460	Sat Nov 28 23:39:58 2020
+++ src/usr.bin/make/parse.c	Sun Nov 29 00:04:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.460 2020/11/28 23:39:58 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.461 2020/11/29 00:04:22 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.460 2020/11/28 23:39:58 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.461 2020/11/29 00:04:22 rillig Exp $");
 
 /* types and constants */
 
@@ -208,7 +208,7 @@ static GNodeList *targets;
  * with duplicates.  Kept in a separate list since the commands from .USE or
  * .USEBEFORE nodes are shared with other GNodes, thereby giving up the
  * easily understandable ownership over the allocated strings. */
-static StringList *targCmds;
+static StringList targCmds = LST_INIT;
 #endif
 
 /*
@@ -2862,7 +2862,7 @@ ParseLine_ShellCommand(const char *p)
 	    ParseAddCmd(gn, cmd);
 	}
 #ifdef CLEANUP
-	Lst_Append(targCmds, cmd);
+	Lst_Append(&targCmds, cmd);
 #endif
     }
 }
@@ -3115,9 +3115,6 @@ Parse_Init(void)
     sysIncPath = SearchPath_New();
     defSysIncPath = SearchPath_New();
     Vector_Init(&includes, sizeof(IFile));
-#ifdef CLEANUP
-    targCmds = Lst_New();
-#endif
 }
 
 /* Clean up the parsing module. */
@@ -3125,7 +3122,7 @@ void
 Parse_End(void)
 {
 #ifdef CLEANUP
-    Lst_Destroy(targCmds, free);
+    Lst_DoneCall(&targCmds, free);
     assert(targets == NULL);
     SearchPath_Free(defSysIncPath);
     SearchPath_Free(sysIncPath);
@@ -3140,13 +3137,9 @@ Parse_End(void)
  * Return a list containing the single main target to create.
  * If no such target exists, we Punt with an obnoxious error message.
  */
-GNodeList *
-Parse_MainName(void)
+void
+Parse_MainName(GNodeList *mainList)
 {
-    GNodeList *mainList;
-
-    mainList = Lst_New();
-
     if (mainNode == NULL)
 	Punt("no target to make.");
 
@@ -3157,8 +3150,6 @@ Parse_MainName(void)
 	Lst_Append(mainList, mainNode);
 
     Var_Append(".TARGETS", mainNode->name, VAR_GLOBAL);
-
-    return mainList;
 }
 
 int

Index: src/usr.bin/make/targ.c
diff -u src/usr.bin/make/targ.c:1.146 src/usr.bin/make/targ.c:1.147
--- src/usr.bin/make/targ.c:1.146	Sat Nov 28 19:22:32 2020
+++ src/usr.bin/make/targ.c	Sun Nov 29 00:04:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: targ.c,v 1.146 2020/11/28 19:22:32 rillig Exp $	*/
+/*	$NetBSD: targ.c,v 1.147 2020/11/29 00:04:22 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -119,7 +119,7 @@
 #include "dir.h"
 
 /*	"@(#)targ.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: targ.c,v 1.146 2020/11/28 19:22:32 rillig Exp $");
+MAKE_RCSID("$NetBSD: targ.c,v 1.147 2020/11/29 00:04:22 rillig Exp $");
 
 /*
  * All target nodes that appeared on the left-hand side of one of the
@@ -311,17 +311,15 @@ GNode *Targ_GetEndNode(void)
 }
 
 /* Return the named nodes, creating them as necessary. */
-GNodeList *
-Targ_FindList(StringList *names)
+void
+Targ_FindList(GNodeList *nodes, StringList *names)
 {
     StringListNode *ln;
-    GNodeList *nodes = Lst_New();
     for (ln = names->first; ln != NULL; ln = ln->next) {
 	const char *name = ln->datum;
 	GNode *gn = Targ_GetNode(name);
 	Lst_Append(nodes, gn);
     }
-    return nodes;
 }
 
 /* Return true if should ignore errors when creating gn. */

Reply via email to