Module Name:    src
Committed By:   rillig
Date:           Thu Sep 24 07:23:26 UTC 2020

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

Log Message:
make(1): merge Lst_ForEachFrom into Lst_ForEachUntil


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/usr.bin/make/lst.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.67 src/usr.bin/make/lst.c:1.68
--- src/usr.bin/make/lst.c:1.67	Thu Sep 24 07:11:29 2020
+++ src/usr.bin/make/lst.c	Thu Sep 24 07:23:26 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.67 2020/09/24 07:11:29 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.68 2020/09/24 07:23:26 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -36,7 +36,7 @@
 
 #include "make.h"
 
-MAKE_RCSID("$NetBSD: lst.c,v 1.67 2020/09/24 07:11:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: lst.c,v 1.68 2020/09/24 07:23:26 rillig Exp $");
 
 struct ListNode {
     struct ListNode *prev;	/* previous element in list */
@@ -415,42 +415,21 @@ Lst_FindDatum(List *list, const void *da
     return NULL;
 }
 
-static int Lst_ForEachFrom(List *, ListNode *, LstActionUntilProc, void *);
-
 /* Apply the given function to each element of the given list. The function
  * should return 0 if traversal should continue and non-zero if it should
  * abort. */
 int
 Lst_ForEachUntil(List *list, LstActionUntilProc proc, void *procData)
 {
-    if (LstIsEmpty(list))
-	return 0;		/* XXX: Document what this value means. */
-    return Lst_ForEachFrom(list, Lst_First(list), proc, procData);
-}
-
-/* Apply the given function to each element of the given list, starting from
- * the given node. The function should return 0 if traversal should continue,
- * and non-zero if it should abort. */
-int
-Lst_ForEachFrom(List *list, ListNode *node,
-		 LstActionUntilProc proc, void *procData)
-{
-    ListNode *tln = node;
-    ListNode *next;
-    Boolean done;
-    int result;
+    ListNode *tln = list->first;
+    int result = 0;
 
-    assert(list != NULL);
-    assert(node != NULL);
-    assert(proc != NULL);
-
-    do {
+    while (tln != NULL) {
 	/*
 	 * Take care of having the current element deleted out from under
 	 * us.
 	 */
-
-	next = tln->next;
+    	ListNode *next = tln->next;
 
 	/*
 	 * We're done with the traversal if
@@ -458,7 +437,7 @@ Lst_ForEachFrom(List *list, ListNode *no
 	 *  - nothing's been added after the current node (check this
 	 *    after proc() has been called).
 	 */
-	done = next == NULL;
+	Boolean done = next == NULL;
 
 	tln->useCount++;
 	result = (*proc)(tln->datum, procData);
@@ -478,7 +457,9 @@ Lst_ForEachFrom(List *list, ListNode *no
 	    free((char *)tln);
 	}
 	tln = next;
-    } while (!result && !LstIsEmpty(list) && !done);
+	if (result || LstIsEmpty(list) || done)
+	    break;
+    }
 
     return result;
 }

Reply via email to