Module Name:    src
Committed By:   rillig
Date:           Sat Aug 22 13:06:40 UTC 2020

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

Log Message:
make(1): make Make_HandleUse simpler

Since the function names now contain the text from the comments, the
comments can be shortened a bit.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/make/lst.c
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/make/lst.h
cvs rdiff -u -r1.111 -r1.112 src/usr.bin/make/make.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/lst.c
diff -u src/usr.bin/make/lst.c:1.21 src/usr.bin/make/lst.c:1.22
--- src/usr.bin/make/lst.c:1.21	Sat Aug 22 09:40:18 2020
+++ src/usr.bin/make/lst.c	Sat Aug 22 13:06:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.21 2020/08/22 09:40:18 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.22 2020/08/22 13:06:39 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.21 2020/08/22 09:40:18 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.22 2020/08/22 13:06:39 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.21 2020/08/22 09:40:18 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.22 2020/08/22 13:06:39 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -83,12 +83,14 @@ LstNodeIsValid(LstNode node)
     return node != NULL;
 }
 
+/* Allocate and initialize a list node.
+ *
+ * The fields 'prev' and 'next' must be initialized by the caller.
+ */
 static LstNode
 LstNodeNew(void *datum)
 {
     LstNode node = bmake_malloc(sizeof *node);
-    /* prev will be initialized by the calling code. */
-    /* next will be initialized by the calling code. */
     node->useCount = 0;
     node->deleted = FALSE;
     node->datum = datum;
@@ -280,6 +282,28 @@ Lst_AtEnd(Lst list, void *datum)
     return Lst_InsertAfter(list, end, datum);
 }
 
+/* Add a piece of data at the start of the given list. */
+void
+Lst_PrependS(Lst list, void *datum)
+{
+    LstNode node;
+
+    assert(LstIsValid(list));
+    assert(datum != NULL);
+
+    node = LstNodeNew(datum);
+    node->prev = NULL;
+    node->next = list->first;
+
+    if (list->first == NULL) {
+	list->first = node;
+	list->last = node;
+    } else {
+	list->first->prev = node;
+	list->first = node;
+    }
+}
+
 /* Add a piece of data at the end of the given list. */
 void
 Lst_AppendS(Lst list, void *datum)
@@ -640,6 +664,23 @@ Lst_Concat(Lst list1, Lst list2, int fla
     return SUCCESS;
 }
 
+/* Copy the element data from src to the start of dst. */
+void
+Lst_PrependAllS(Lst dst, Lst src)
+{
+    LstNode node;
+    for (node = src->last; node != NULL; node = node->prev)
+        Lst_PrependS(dst, node->datum);
+}
+
+/* Copy the element data from src to the end of dst. */
+void
+Lst_AppendAllS(Lst dst, Lst src)
+{
+    LstNode node;
+    for (node = src->first; node != NULL; node = node->next)
+        Lst_AppendS(dst, node->datum);
+}
 
 /*
  * these functions are for dealing with a list as a table, of sorts.

Index: src/usr.bin/make/lst.h
diff -u src/usr.bin/make/lst.h:1.28 src/usr.bin/make/lst.h:1.29
--- src/usr.bin/make/lst.h:1.28	Sat Aug 22 09:40:18 2020
+++ src/usr.bin/make/lst.h	Sat Aug 22 13:06:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lst.h,v 1.28 2020/08/22 09:40:18 rillig Exp $	*/
+/*	$NetBSD: lst.h,v 1.29 2020/08/22 13:06:39 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -119,6 +119,7 @@ ReturnStatus	Lst_InsertBefore(Lst, LstNo
 ReturnStatus	Lst_InsertAfter(Lst, LstNode, void *);
 /* Place an element at the front of a lst. */
 ReturnStatus	Lst_AtFront(Lst, void *);
+void		Lst_PrependS(Lst, void *);
 /* Place an element at the end of a lst. */
 ReturnStatus	Lst_AtEnd(Lst, void *);
 void		Lst_AppendS(Lst, void *);
@@ -128,6 +129,8 @@ void		Lst_RemoveS(Lst, LstNode);
 void		Lst_ReplaceS(LstNode, void *);
 /* Concatenate two lists */
 ReturnStatus	Lst_Concat(Lst, Lst, int);
+void		Lst_PrependAllS(Lst, Lst);
+void		Lst_AppendAllS(Lst, Lst);
 
 /*
  * Node-specific functions

Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.111 src/usr.bin/make/make.c:1.112
--- src/usr.bin/make/make.c:1.111	Sat Aug 22 11:57:18 2020
+++ src/usr.bin/make/make.c	Sat Aug 22 13:06:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.c,v 1.111 2020/08/22 11:57:18 rillig Exp $	*/
+/*	$NetBSD: make.c,v 1.112 2020/08/22 13:06:39 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.111 2020/08/22 11:57:18 rillig Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.112 2020/08/22 13:06:39 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.111 2020/08/22 11:57:18 rillig Exp $");
+__RCSID("$NetBSD: make.c,v 1.112 2020/08/22 13:06:39 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -439,21 +439,11 @@ Make_HandleUse(GNode *cgn, GNode *pgn)
 
     if ((cgn->type & (OP_USE|OP_USEBEFORE)) || Lst_IsEmpty(pgn->commands)) {
 	    if (cgn->type & OP_USEBEFORE) {
-		/*
-		 * .USEBEFORE --
-		 *	prepend the child's commands to the parent.
-		 */
-		LstNode node;
-		for (node = Lst_Last(cgn->commands);
-		     node != NULL;
-		     node = Lst_Prev(node))
-		    Lst_AtFront(pgn->commands, Lst_Datum(node));
+		/* .USEBEFORE */
+		Lst_PrependAllS(pgn->commands, cgn->commands);
 	    } else {
-		/*
-		 * .USE or target has no commands --
-		 *	append the child's commands to the parent.
-		 */
-		(void)Lst_Concat(pgn->commands, cgn->commands, LST_CONCNEW);
+		/* .USE, or target has no commands */
+		Lst_AppendAllS(pgn->commands, cgn->commands);
 	    }
     }
 

Reply via email to