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

Modified Files:
        src/usr.bin/make: arch.c lst.h

Log Message:
make(1): reduce memory allocation in Arch_ParseArchive


To generate a diff of this commit:
cvs rdiff -u -r1.180 -r1.181 src/usr.bin/make/arch.c
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/make/lst.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/arch.c
diff -u src/usr.bin/make/arch.c:1.180 src/usr.bin/make/arch.c:1.181
--- src/usr.bin/make/arch.c:1.180	Sat Nov 28 19:26:10 2020
+++ src/usr.bin/make/arch.c	Sat Nov 28 23:13:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.180 2020/11/28 19:26:10 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.181 2020/11/28 23:13:28 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.180 2020/11/28 19:26:10 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.181 2020/11/28 23:13:28 rillig Exp $");
 
 typedef struct List ArchList;
 typedef struct ListNode ArchListNode;
@@ -344,11 +344,11 @@ Arch_ParseArchive(char **pp, GNodeList *
 			free(buf);
 
 		} else if (Dir_HasWildcards(memName)) {
-			StringList *members = Lst_New();
-			Dir_Expand(memName, dirSearchPath, members);
+			StringList members = LST_INIT;
+			Dir_Expand(memName, dirSearchPath, &members);
 
-			while (!Lst_IsEmpty(members)) {
-				char *member = Lst_Dequeue(members);
+			while (!Lst_IsEmpty(&members)) {
+				char *member = Lst_Dequeue(&members);
 				char *fullname = str_concat4(libName, "(",
 							     member, ")");
 				free(member);
@@ -359,7 +359,7 @@ Arch_ParseArchive(char **pp, GNodeList *
 				gn->type |= OP_ARCHV;
 				Lst_Append(nodeLst, gn);
 			}
-			Lst_Free(members);
+			Lst_Done(&members);
 
 		} else {
 			char *fullname = str_concat4(libName, "(", memName,

Index: src/usr.bin/make/lst.h
diff -u src/usr.bin/make/lst.h:1.89 src/usr.bin/make/lst.h:1.90
--- src/usr.bin/make/lst.h:1.89	Sat Nov 28 19:26:10 2020
+++ src/usr.bin/make/lst.h	Sat Nov 28 23:13:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lst.h,v 1.89 2020/11/28 19:26:10 rillig Exp $	*/
+/*	$NetBSD: lst.h,v 1.90 2020/11/28 23:13:28 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -118,6 +118,8 @@ void Lst_Free(List *);
 /* Free the list, freeing the node data using the given function. */
 void Lst_Destroy(List *, LstFreeProc);
 
+#define LST_INIT { NULL, NULL }
+
 /* Initialize a list, without memory allocation. */
 MAKE_INLINE void
 Lst_Init(List *list)

Reply via email to