Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): remove Lst_Open, Lst_Next, Lst_Close



details:   https://anonhg.NetBSD.org/src/rev/f8ea072c4088
branches:  trunk
changeset: 945155:f8ea072c4088
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Oct 22 20:18:20 2020 +0000

description:
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.

diffstat:

 usr.bin/make/lst.c |  85 +----------------------------------------------------
 usr.bin/make/lst.h |  20 +------------
 2 files changed, 3 insertions(+), 102 deletions(-)

diffs (164 lines):

diff -r 5da0cec51243 -r f8ea072c4088 usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Thu Oct 22 20:13:02 2020 +0000
+++ b/usr.bin/make/lst.c        Thu Oct 22 20:18:20 2020 +0000
@@ -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 @@
 
     list->first = NULL;
     list->last = NULL;
-    list->priv_isOpen = FALSE;
-    list->priv_lastAccess = Unknown;
 
     return list;
 }
@@ -218,19 +216,6 @@
     }
 
     /*
-     * 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 @@
 }
 
 /*
- * 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
  */
 
diff -r 5da0cec51243 -r f8ea072c4088 usr.bin/make/lst.h
--- a/usr.bin/make/lst.h        Thu Oct 22 20:13:02 2020 +0000
+++ b/usr.bin/make/lst.h        Thu Oct 22 20:18:20 2020 +0000
@@ -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 @@
     };
 };
 
-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 @@
 /* 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. */



Home | Main Index | Thread Index | Old Index