Module Name:    src
Committed By:   rillig
Date:           Mon Sep 21 03:12:26 UTC 2020

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

Log Message:
make(1): clean up Arch_ParseArchive

This code is so seldom used that it's not necessary to squeeze out every
little bit of performance.  It's more important for the code to be clear
and simple.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/usr.bin/make/arch.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.115 src/usr.bin/make/arch.c:1.116
--- src/usr.bin/make/arch.c:1.115	Sun Sep 13 18:27:39 2020
+++ src/usr.bin/make/arch.c	Mon Sep 21 03:12:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.115 2020/09/13 18:27:39 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.116 2020/09/21 03:12:25 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -133,7 +133,7 @@
 #include    "config.h"
 
 /*	"@(#)arch.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: arch.c,v 1.115 2020/09/13 18:27:39 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.116 2020/09/21 03:12:25 rillig Exp $");
 
 #ifdef TARGET_MACHINE
 #undef MAKE_MACHINE
@@ -362,62 +362,47 @@ Arch_ParseArchive(char **linePtr, Lst no
 	    free(buf);
 	} else if (Dir_HasWildcards(memName)) {
 	    Lst members = Lst_Init();
-	    Buffer nameBuf;
-
-	    Buf_Init(&nameBuf, 0);
 	    Dir_Expand(memName, dirSearchPath, members);
+
 	    while (!Lst_IsEmpty(members)) {
 		char *member = Lst_Dequeue(members);
-
-		Buf_Empty(&nameBuf);
-		Buf_AddStr(&nameBuf, libName);
-		Buf_AddStr(&nameBuf, "(");
-		Buf_AddStr(&nameBuf, member);
-		Buf_AddStr(&nameBuf, ")");
+		char *fullname = str_concat4(libName, "(", member, ")");
 		free(member);
 
-		gn = Targ_FindNode(Buf_GetAll(&nameBuf, NULL), TARG_CREATE);
-		if (gn == NULL) {
-		    Buf_Destroy(&nameBuf, TRUE);
+		gn = Targ_FindNode(fullname, TARG_CREATE);
+		free(fullname);
+
+		if (gn == NULL)
 		    return FALSE;
-		} else {
-		    /*
-		     * We've found the node, but have to make sure the rest of
-		     * the world knows it's an archive member, without having
-		     * to constantly check for parentheses, so we type the
-		     * thing with the OP_ARCHV bit before we place it on the
-		     * end of the provided list.
-		     */
-		    gn->type |= OP_ARCHV;
-		    Lst_Append(nodeLst, gn);
-		}
-	    }
-	    Lst_Free(members);
-	    Buf_Destroy(&nameBuf, TRUE);
-	} else {
-	    Buffer nameBuf;
 
-	    Buf_Init(&nameBuf, 0);
-	    Buf_AddStr(&nameBuf, libName);
-	    Buf_AddStr(&nameBuf, "(");
-	    Buf_AddStr(&nameBuf, memName);
-	    Buf_AddStr(&nameBuf, ")");
-
-	    gn = Targ_FindNode(Buf_GetAll(&nameBuf, NULL), TARG_CREATE);
-	    Buf_Destroy(&nameBuf, TRUE);
-	    if (gn == NULL) {
-		return FALSE;
-	    } else {
 		/*
-		 * We've found the node, but have to make sure the rest of the
-		 * world knows it's an archive member, without having to
-		 * constantly check for parentheses, so we type the thing with
-		 * the OP_ARCHV bit before we place it on the end of the
-		 * provided list.
+		 * We've found the node, but have to make sure the rest of
+		 * the world knows it's an archive member, without having
+		 * to constantly check for parentheses, so we type the
+		 * thing with the OP_ARCHV bit before we place it on the
+		 * end of the provided list.
 		 */
 		gn->type |= OP_ARCHV;
 		Lst_Append(nodeLst, gn);
 	    }
+	    Lst_Free(members);
+	} else {
+	    char *fullname = str_concat4(libName, "(", memName, ")");
+	    gn = Targ_FindNode(fullname, TARG_CREATE);
+	    free(fullname);
+
+	    if (gn == NULL)
+		return FALSE;
+
+	    /*
+	     * We've found the node, but have to make sure the rest of the
+	     * world knows it's an archive member, without having to
+	     * constantly check for parentheses, so we type the thing with
+	     * the OP_ARCHV bit before we place it on the end of the
+	     * provided list.
+	     */
+	    gn->type |= OP_ARCHV;
+	    Lst_Append(nodeLst, gn);
 	}
 	if (doSubst) {
 	    free(memName);

Reply via email to