Module Name:    src
Committed By:   rillig
Date:           Sun Nov 29 01:40:26 UTC 2020

Modified Files:
        src/usr.bin/make: arch.c cond.c dir.c main.c make.h parse.c suff.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.181 -r1.182 src/usr.bin/make/arch.c
cvs rdiff -u -r1.219 -r1.220 src/usr.bin/make/cond.c
cvs rdiff -u -r1.227 -r1.228 src/usr.bin/make/dir.c
cvs rdiff -u -r1.489 -r1.490 src/usr.bin/make/main.c
cvs rdiff -u -r1.228 -r1.229 src/usr.bin/make/make.h
cvs rdiff -u -r1.462 -r1.463 src/usr.bin/make/parse.c
cvs rdiff -u -r1.322 -r1.323 src/usr.bin/make/suff.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/arch.c
diff -u src/usr.bin/make/arch.c:1.181 src/usr.bin/make/arch.c:1.182
--- src/usr.bin/make/arch.c:1.181	Sat Nov 28 23:13:28 2020
+++ src/usr.bin/make/arch.c	Sun Nov 29 01:40:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.181 2020/11/28 23:13:28 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.182 2020/11/29 01:40:26 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -125,7 +125,7 @@
 #include "config.h"
 
 /*	"@(#)arch.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: arch.c,v 1.181 2020/11/28 23:13:28 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.182 2020/11/29 01:40:26 rillig Exp $");
 
 typedef struct List ArchList;
 typedef struct ListNode ArchListNode;
@@ -345,7 +345,7 @@ Arch_ParseArchive(char **pp, GNodeList *
 
 		} else if (Dir_HasWildcards(memName)) {
 			StringList members = LST_INIT;
-			Dir_Expand(memName, dirSearchPath, &members);
+			Dir_Expand(memName, &dirSearchPath, &members);
 
 			while (!Lst_IsEmpty(&members)) {
 				char *member = Lst_Dequeue(&members);

Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.219 src/usr.bin/make/cond.c:1.220
--- src/usr.bin/make/cond.c:1.219	Sat Nov 28 23:39:58 2020
+++ src/usr.bin/make/cond.c	Sun Nov 29 01:40:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.219 2020/11/28 23:39:58 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.220 2020/11/29 01:40:26 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -94,7 +94,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.219 2020/11/28 23:39:58 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.220 2020/11/29 01:40:26 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -313,7 +313,7 @@ FuncExists(size_t argLen MAKE_ATTR_UNUSE
 	Boolean result;
 	char *path;
 
-	path = Dir_FindFile(arg, dirSearchPath);
+	path = Dir_FindFile(arg, &dirSearchPath);
 	DEBUG2(COND, "exists(%s) result is \"%s\"\n",
 	       arg, path != NULL ? path : "");
 	result = path != NULL;

Index: src/usr.bin/make/dir.c
diff -u src/usr.bin/make/dir.c:1.227 src/usr.bin/make/dir.c:1.228
--- src/usr.bin/make/dir.c:1.227	Sat Nov 28 23:22:14 2020
+++ src/usr.bin/make/dir.c	Sun Nov 29 01:40:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.227 2020/11/28 23:22:14 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.228 2020/11/29 01:40:26 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -136,7 +136,7 @@
 #include "job.h"
 
 /*	"@(#)dir.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: dir.c,v 1.227 2020/11/28 23:22:14 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.228 2020/11/29 01:40:26 rillig Exp $");
 
 #define DIR_DEBUG0(text) DEBUG0(DIR, text)
 #define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1)
@@ -214,7 +214,7 @@ typedef ListNode CachedDirListNode;
 
 typedef ListNode SearchPathNode;
 
-SearchPath *dirSearchPath;	/* main search path */
+SearchPath dirSearchPath = LST_INIT;	/* main search path */
 
 /* A list of cached directories, with fast lookup by directory name. */
 typedef struct OpenDirs {
@@ -368,7 +368,6 @@ cached_lstat(const char *pathname, struc
 void
 Dir_Init(void)
 {
-	dirSearchPath = SearchPath_New();
 	OpenDirs_Init(&openDirs);
 	HashTable_Init(&mtimes);
 	HashTable_Init(&lmtimes);
@@ -459,8 +458,7 @@ Dir_End(void)
 	dotLast->refCount--;
 	Dir_Destroy(dotLast);
 	Dir_Destroy(dot);
-	SearchPath_Clear(dirSearchPath);
-	Lst_Free(dirSearchPath);
+	SearchPath_Clear(&dirSearchPath);
 	OpenDirs_Done(&openDirs);
 	HashTable_Done(&mtimes);
 #endif
@@ -479,7 +477,7 @@ Dir_SetPATH(void)
 
 	Var_Delete(".PATH", VAR_GLOBAL);
 
-	if ((ln = dirSearchPath->first) != NULL) {
+	if ((ln = dirSearchPath.first) != NULL) {
 		CachedDir *dir = ln->datum;
 		if (dir == dotLast) {
 			hasLastDot = TRUE;
@@ -494,7 +492,7 @@ Dir_SetPATH(void)
 			Var_Append(".PATH", cur->name, VAR_GLOBAL);
 	}
 
-	for (ln = dirSearchPath->first; ln != NULL; ln = ln->next) {
+	for (ln = dirSearchPath.first; ln != NULL; ln = ln->next) {
 		CachedDir *dir = ln->datum;
 		if (dir == dotLast)
 			continue;
@@ -1481,7 +1479,7 @@ Dir_CopyDirSearchPath(void)
 {
 	SearchPath *path = SearchPath_New();
 	SearchPathNode *ln;
-	for (ln = dirSearchPath->first; ln != NULL; ln = ln->next) {
+	for (ln = dirSearchPath.first; ln != NULL; ln = ln->next) {
 		CachedDir *dir = ln->datum;
 		dir->refCount++;
 		Lst_Append(path, dir);

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.489 src/usr.bin/make/main.c:1.490
--- src/usr.bin/make/main.c:1.489	Sun Nov 29 00:42:01 2020
+++ src/usr.bin/make/main.c	Sun Nov 29 01:40:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.489 2020/11/29 00:42:01 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.490 2020/11/29 01:40:26 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.489 2020/11/29 00:42:01 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.490 2020/11/29 01:40:26 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	    "The Regents of the University of California.  "
@@ -1288,7 +1288,7 @@ InitVpath(void)
 		savec = *cp;
 		*cp = '\0';
 		/* Add directory to search path */
-		(void)Dir_AddDir(dirSearchPath, path);
+		(void)Dir_AddDir(&dirSearchPath, path);
 		*cp = savec;
 		path = cp + 1;
 	} while (savec == ':');

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.228 src/usr.bin/make/make.h:1.229
--- src/usr.bin/make/make.h:1.228	Sat Nov 28 23:39:58 2020
+++ src/usr.bin/make/make.h	Sun Nov 29 01:40:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.228 2020/11/28 23:39:58 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.229 2020/11/29 01:40:26 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -508,7 +508,7 @@ extern Boolean preserveUndefined;
 
 /* The list of directories to search when looking for targets (set by the
  * special target .PATH). */
-extern SearchPath *dirSearchPath;
+extern SearchPath dirSearchPath;
 /* Used for .include "...". */
 extern SearchPath *parseIncPath;
 /* Used for .include <...>, for the built-in sys.mk and makefiles from the

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.462 src/usr.bin/make/parse.c:1.463
--- src/usr.bin/make/parse.c:1.462	Sun Nov 29 01:35:33 2020
+++ src/usr.bin/make/parse.c	Sun Nov 29 01:40:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.462 2020/11/29 01:35:33 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.463 2020/11/29 01:40:26 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.462 2020/11/29 01:35:33 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.463 2020/11/29 01:40:26 rillig Exp $");
 
 /* types and constants */
 
@@ -1087,7 +1087,7 @@ ParseDoDependencyTargetSpecial(ParseSpec
     case SP_PATH:
 	if (*inout_paths == NULL)
 	    *inout_paths = Lst_New();
-	Lst_Append(*inout_paths, dirSearchPath);
+	Lst_Append(*inout_paths, &dirSearchPath);
 	break;
     case SP_MAIN:
 	/* Allow targets from the command line to override the .MAIN node. */
@@ -2132,7 +2132,7 @@ Parse_include_file(char *file, Boolean i
 	    newName = str_concat3(incdir, "/", file + i);
 	    fullname = Dir_FindFile(newName, parseIncPath);
 	    if (fullname == NULL)
-		fullname = Dir_FindFile(newName, dirSearchPath);
+		fullname = Dir_FindFile(newName, &dirSearchPath);
 	    free(newName);
 	}
 	free(incdir);
@@ -2155,7 +2155,7 @@ Parse_include_file(char *file, Boolean i
 	    if (fullname == NULL) {
 		fullname = Dir_FindFile(file, parseIncPath);
 		if (fullname == NULL)
-		    fullname = Dir_FindFile(file, dirSearchPath);
+		    fullname = Dir_FindFile(file, &dirSearchPath);
 	    }
 	}
     }

Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.322 src/usr.bin/make/suff.c:1.323
--- src/usr.bin/make/suff.c:1.322	Sun Nov 29 01:30:38 2020
+++ src/usr.bin/make/suff.c	Sun Nov 29 01:40:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.322 2020/11/29 01:30:38 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.323 2020/11/29 01:40:26 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -114,7 +114,7 @@
 #include "dir.h"
 
 /*	"@(#)suff.c	8.4 (Berkeley) 3/21/94"	*/
-MAKE_RCSID("$NetBSD: suff.c,v 1.322 2020/11/29 01:30:38 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.323 2020/11/29 01:40:26 rillig Exp $");
 
 #define SUFF_DEBUG0(text) DEBUG0(SUFF, text)
 #define SUFF_DEBUG1(fmt, arg1) DEBUG1(SUFF, fmt, arg1)
@@ -467,7 +467,7 @@ Suff_ClearSuffixes(void)
 	SuffFree(nullSuff);
     emptySuff = nullSuff = Suffix_New("");
 
-    SearchPath_AddAll(nullSuff->searchPath, dirSearchPath);
+    SearchPath_AddAll(nullSuff->searchPath, &dirSearchPath);
     nullSuff->flags = SUFF_NULL;
 }
 
@@ -849,7 +849,7 @@ Suff_DoPaths(void)
 	    if (suff->flags & SUFF_LIBRARY)
 		SearchPath_AddAll(inLibs, suff->searchPath);
 #endif
-	    SearchPath_AddAll(suff->searchPath, dirSearchPath);
+	    SearchPath_AddAll(suff->searchPath, &dirSearchPath);
 	} else {
 	    SearchPath_Free(suff->searchPath);
 	    suff->searchPath = Dir_CopyDirSearchPath();
@@ -1423,7 +1423,7 @@ Suff_FindPath(GNode* gn)
 	return suff->searchPath;
     } else {
 	SUFF_DEBUG0("\n");
-	return dirSearchPath;	/* Use default search path */
+	return &dirSearchPath;	/* Use default search path */
     }
 }
 
@@ -1726,7 +1726,7 @@ FindDepsRegularPath(GNode *gn, Candidate
 
     free(gn->path);
     gn->path = Dir_FindFile(gn->name,
-			    (targ == NULL ? dirSearchPath :
+			    (targ == NULL ? &dirSearchPath :
 			     targ->suff->searchPath));
     if (gn->path == NULL)
 	return;

Reply via email to