Module Name:    src
Committed By:   rillig
Date:           Thu Oct 22 20:18:20 UTC 2020

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

Log Message:
make(1): remove Lst_Open, Lst_Next, Lst_Close

These functions had made the Lst data type more complicated and hard to
understand than necessary.  This additional complexity was not needed in
the vast majority of the cases.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/make/lst.c
cvs rdiff -u -r1.75 -r1.76 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/lst.c
diff -u src/usr.bin/make/lst.c:1.80 src/usr.bin/make/lst.c:1.81
--- src/usr.bin/make/lst.c:1.80	Thu Oct 22 19:14:06 2020
+++ src/usr.bin/make/lst.c	Thu Oct 22 20:18:20 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.80 2020/10/22 19:14:06 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.81 2020/10/22 20:18:20 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -34,7 +34,7 @@
 
 #include "make.h"
 
-MAKE_RCSID("$NetBSD: lst.c,v 1.80 2020/10/22 19:14:06 rillig Exp $");
+MAKE_RCSID("$NetBSD: lst.c,v 1.81 2020/10/22 20:18:20 rillig Exp $");
 
 /* Allocate and initialize a list node.
  *
@@ -64,8 +64,6 @@ Lst_New(void)
 
     list->first = NULL;
     list->last = NULL;
-    list->priv_isOpen = FALSE;
-    list->priv_lastAccess = Unknown;
 
     return list;
 }
@@ -218,19 +216,6 @@ Lst_Remove(List *list, ListNode *node)
     }
 
     /*
-     * Sequential access stuff. If the node we're removing is the current
-     * node in the list, reset the current node to the previous one. If the
-     * previous one was non-existent (prev == NULL), we set the
-     * end to be Unknown, since it is.
-     */
-    if (list->priv_isOpen && list->priv_curr == node) {
-	list->priv_curr = list->priv_prev;
-	if (list->priv_curr == NULL) {
-	    list->priv_lastAccess = Unknown;
-	}
-    }
-
-    /*
      * note that the datum is unmolested. The caller must free it as
      * necessary and as expected.
      */
@@ -392,72 +377,6 @@ Lst_AppendAll(List *dst, List *src)
 }
 
 /*
- * these functions are for dealing with a list as a table, of sorts.
- * An idea of the "current element" is kept and used by all the functions
- * between Lst_Open() and Lst_Close().
- *
- * The sequential functions access the list in a slightly different way.
- * CurPtr points to their idea of the current node in the list and they
- * access the list based on it.
- */
-
-/* Open a list for sequential access. A list can still be searched, etc.,
- * without confusing these functions. */
-void
-Lst_Open(List *list)
-{
-    assert(!list->priv_isOpen);
-
-    list->priv_isOpen = TRUE;
-    list->priv_lastAccess = LstIsEmpty(list) ? Head : Unknown;
-    list->priv_curr = NULL;
-}
-
-/* Return the next node for the given list, or NULL if the end has been
- * reached. */
-ListNode *
-Lst_Next(List *list)
-{
-    ListNode *node;
-
-    assert(list->priv_isOpen);
-
-    list->priv_prev = list->priv_curr;
-
-    if (list->priv_curr == NULL) {
-	if (list->priv_lastAccess == Unknown) {
-	    /*
-	     * If we're just starting out, lastAccess will be Unknown.
-	     * Then we want to start this thing off in the right
-	     * direction -- at the start with lastAccess being Middle.
-	     */
-	    list->priv_curr = node = list->first;
-	    list->priv_lastAccess = Middle;
-	} else {
-	    node = NULL;
-	    list->priv_lastAccess = Tail;
-	}
-    } else {
-	node = list->priv_curr->next;
-	list->priv_curr = node;
-	list->priv_lastAccess = node == NULL ? Tail : Middle;
-    }
-
-    return node;
-}
-
-/* Close a list which was opened for sequential access. */
-void
-Lst_Close(List *list)
-{
-    assert(list->priv_isOpen);
-
-    list->priv_isOpen = FALSE;
-    list->priv_lastAccess = Unknown;
-}
-
-
-/*
  * for using the list as a queue
  */
 

Index: src/usr.bin/make/lst.h
diff -u src/usr.bin/make/lst.h:1.75 src/usr.bin/make/lst.h:1.76
--- src/usr.bin/make/lst.h:1.75	Wed Oct 21 07:14:22 2020
+++ src/usr.bin/make/lst.h	Thu Oct 22 20:18:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lst.h,v 1.75 2020/10/21 07:14:22 rillig Exp $	*/
+/*	$NetBSD: lst.h,v 1.76 2020/10/22 20:18:20 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -101,20 +101,9 @@ struct ListNode {
     };
 };
 
-typedef enum ListForEachUntilWhere {
-    Head, Middle, Tail, Unknown
-} ListForEachUntilWhere;
-
 struct List {
     ListNode *first;		/* first node in list */
     ListNode *last;		/* last node in list */
-
-    /* fields for sequential access */
-    Boolean priv_isOpen;	/* true if list has been Lst_Open'ed */
-    ListForEachUntilWhere priv_lastAccess;
-    ListNode *priv_curr;	/* current node, if open. NULL if
-				 * *just* opened */
-    ListNode *priv_prev;	/* Previous node, if open. Used by Lst_Remove */
 };
 
 /* Copy a node, usually by allocating a copy of the given object.
@@ -182,13 +171,6 @@ int Lst_ForEachUntil(List *, LstActionUn
 /* Iterating over a list while keeping track of the current node and possible
  * concurrent modifications */
 
-/* Start iterating the list. */
-void Lst_Open(List *);
-/* Return the next node, or NULL. */
-ListNode *Lst_Next(List *);
-/* Finish iterating the list. */
-void Lst_Close(List *);
-
 /* Using the list as a queue */
 
 /* Add a datum at the tail of the queue. */

Reply via email to