Module Name:    src
Committed By:   rillig
Date:           Sat Aug 22 22:57:53 UTC 2020

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

Log Message:
make(1): replace Lst_Duplicate with Lst_CopyS

Lst_Duplicate would have passed through any null pointer, which was not
needed for make.  It was the last function that used Lst_AtEnd, which in
turn was the last function that used LstInsertAfter.  As a result, these
two functions have been removed.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/usr.bin/make/dir.c
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/make/lst.c
cvs rdiff -u -r1.37 -r1.38 src/usr.bin/make/lst.h
cvs rdiff -u -r1.120 -r1.121 src/usr.bin/make/make.c
cvs rdiff -u -r1.111 -r1.112 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/dir.c
diff -u src/usr.bin/make/dir.c:1.107 src/usr.bin/make/dir.c:1.108
--- src/usr.bin/make/dir.c:1.107	Sat Aug 22 19:57:43 2020
+++ src/usr.bin/make/dir.c	Sat Aug 22 22:57:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.107 2020/08/22 19:57:43 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.108 2020/08/22 22:57:53 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: dir.c,v 1.107 2020/08/22 19:57:43 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.108 2020/08/22 22:57:53 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.107 2020/08/22 19:57:43 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.108 2020/08/22 22:57:53 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1613,15 +1613,11 @@ Dir_AddDir(Lst path, const char *name)
 /*-
  *-----------------------------------------------------------------------
  * Dir_CopyDir --
- *	Callback function for duplicating a search path via Lst_Duplicate.
+ *	Callback function for duplicating a search path via Lst_CopyS.
  *	Ups the reference count for the directory.
  *
  * Results:
  *	Returns the Path it was given.
- *
- * Side Effects:
- *	The refCount of the path is incremented.
- *
  *-----------------------------------------------------------------------
  */
 void *

Index: src/usr.bin/make/lst.c
diff -u src/usr.bin/make/lst.c:1.34 src/usr.bin/make/lst.c:1.35
--- src/usr.bin/make/lst.c:1.34	Sat Aug 22 22:41:42 2020
+++ src/usr.bin/make/lst.c	Sat Aug 22 22:57:53 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.34 2020/08/22 22:41:42 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.35 2020/08/22 22:57:53 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -37,11 +37,11 @@
 #include "make.h"
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: lst.c,v 1.34 2020/08/22 22:41:42 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.35 2020/08/22 22:57:53 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.34 2020/08/22 22:41:42 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.35 2020/08/22 22:57:53 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -71,8 +71,6 @@ struct List {
     LstNode prev;		/* Previous node, if open. Used by Lst_Remove */
 };
 
-static ReturnStatus Lst_AtEnd(Lst, void *);
-
 static Boolean
 LstIsValid(Lst list)
 {
@@ -121,31 +119,20 @@ Lst_Init(void)
 
 /* Duplicate an entire list, usually by copying the datum pointers.
  * If copyProc is given, that function is used to create the new datum from the
- * old datum, usually by creating a copy of it.
- * Return the new list, or NULL on failure. */
+ * old datum, usually by creating a copy of it. */
 Lst
-Lst_Duplicate(Lst list, DuplicateProc *copyProc)
+Lst_CopyS(Lst list, DuplicateProc *copyProc)
 {
     Lst newList;
     LstNode node;
 
-    if (!LstIsValid(list)) {
-	return NULL;
-    }
+    assert(LstIsValid(list));
 
     newList = Lst_Init();
 
-    node = list->first;
-    while (node != NULL) {
-	if (copyProc != NULL) {
-	    if (Lst_AtEnd(newList, copyProc(node->datum)) == FAILURE) {
-		return NULL;
-	    }
-	} else if (Lst_AtEnd(newList, node->datum) == FAILURE) {
-	    return NULL;
-	}
-
-	node = node->next;
+    for (node = list->first; node != NULL; node = node->next) {
+	void *datum = copyProc != NULL ? copyProc(node->datum) : node->datum;
+	Lst_AppendS(newList, datum);
     }
 
     return newList;
@@ -256,44 +243,6 @@ Lst_InsertBeforeS(Lst list, LstNode node
     }
 }
 
-/* Insert a new node with the given piece of data after the given node in the
- * given list. */
-static ReturnStatus
-LstInsertAfter(Lst list, LstNode node, void *datum)
-{
-    LstNode newNode;
-
-    if (LstIsValid(list) && (node == NULL && LstIsEmpty(list))) {
-	goto ok;
-    }
-
-    if (!LstIsValid(list) || LstIsEmpty(list) || !LstNodeIsValid(node)) {
-	return FAILURE;
-    }
-    ok:
-
-    newNode = LstNodeNew(datum);
-
-    if (node == NULL) {
-	newNode->next = newNode->prev = NULL;
-	list->first = list->last = newNode;
-    } else {
-	newNode->prev = node;
-	newNode->next = node->next;
-
-	node->next = newNode;
-	if (newNode->next != NULL) {
-	    newNode->next->prev = newNode;
-	}
-
-	if (node == list->last) {
-	    list->last = newNode;
-	}
-    }
-
-    return SUCCESS;
-}
-
 /* Add a piece of data at the front of the given list. */
 ReturnStatus
 Lst_AtFront(Lst list, void *datum)
@@ -302,14 +251,6 @@ Lst_AtFront(Lst list, void *datum)
     return LstInsertBefore(list, front, datum);
 }
 
-/* Add a piece of data at the end of the given list. */
-ReturnStatus
-Lst_AtEnd(Lst list, void *datum)
-{
-    LstNode end = Lst_Last(list);
-    return LstInsertAfter(list, end, datum);
-}
-
 /* Add a piece of data at the start of the given list. */
 void
 Lst_PrependS(Lst list, void *datum)

Index: src/usr.bin/make/lst.h
diff -u src/usr.bin/make/lst.h:1.37 src/usr.bin/make/lst.h:1.38
--- src/usr.bin/make/lst.h:1.37	Sat Aug 22 22:41:42 2020
+++ src/usr.bin/make/lst.h	Sat Aug 22 22:57:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lst.h,v 1.37 2020/08/22 22:41:42 rillig Exp $	*/
+/*	$NetBSD: lst.h,v 1.38 2020/08/22 22:57:53 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -101,7 +101,7 @@ typedef void		FreeProc(void *);
 /* Create a new list */
 Lst		Lst_Init(void);
 /* Duplicate an existing list */
-Lst		Lst_Duplicate(Lst, DuplicateProc *);
+Lst		Lst_CopyS(Lst, DuplicateProc *);
 /* Destroy an old one */
 void		Lst_Destroy(Lst, FreeProc *);
 /* True if list is empty */

Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.120 src/usr.bin/make/make.c:1.121
--- src/usr.bin/make/make.c:1.120	Sat Aug 22 22:41:42 2020
+++ src/usr.bin/make/make.c	Sat Aug 22 22:57:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.c,v 1.120 2020/08/22 22:41:42 rillig Exp $	*/
+/*	$NetBSD: make.c,v 1.121 2020/08/22 22:57:53 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.120 2020/08/22 22:41:42 rillig Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.121 2020/08/22 22:57:53 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)make.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: make.c,v 1.120 2020/08/22 22:41:42 rillig Exp $");
+__RCSID("$NetBSD: make.c,v 1.121 2020/08/22 22:57:53 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1258,7 +1258,7 @@ Make_ExpandUse(Lst targs)
     GNode  *gn;		/* a temporary pointer */
     Lst    examine; 	/* List of targets to examine */
 
-    examine = Lst_Duplicate(targs, NULL);
+    examine = Lst_CopyS(targs, NULL);
 
     /*
      * Make an initial downward pass over the graph, marking nodes to be made

Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.111 src/usr.bin/make/suff.c:1.112
--- src/usr.bin/make/suff.c:1.111	Sat Aug 22 22:41:42 2020
+++ src/usr.bin/make/suff.c	Sat Aug 22 22:57:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.111 2020/08/22 22:41:42 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.112 2020/08/22 22:57:53 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.111 2020/08/22 22:41:42 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.112 2020/08/22 22:57:53 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)suff.c	8.4 (Berkeley) 3/21/94";
 #else
-__RCSID("$NetBSD: suff.c,v 1.111 2020/08/22 22:41:42 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.112 2020/08/22 22:57:53 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1085,7 +1085,7 @@ Suff_DoPaths(void)
 	    Dir_Concat(s->searchPath, dirSearchPath);
 	} else {
 	    Lst_Destroy(s->searchPath, Dir_Destroy);
-	    s->searchPath = Lst_Duplicate(dirSearchPath, Dir_CopyDir);
+	    s->searchPath = Lst_CopyS(dirSearchPath, Dir_CopyDir);
 	}
     }
     Lst_CloseS(sufflist);

Reply via email to