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): add Lst_Append to add an item at the e...



details:   https://anonhg.NetBSD.org/src/rev/400fca9ae5b3
branches:  trunk
changeset: 1013160:400fca9ae5b3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 22 09:40:18 2020 +0000

description:
make(1): add Lst_Append to add an item at the end of the list

The previous variant of using a special case of Lst_InsertAfter was
unnecessarily complicated.  Linked lists are a very basic data
structure, and there is no need to overcomplicate things by introducing
unnecessary conditions and branches.

diffstat:

 usr.bin/make/dir.c |   8 ++++----
 usr.bin/make/lst.c |  30 ++++++++++++++++++++++++++----
 usr.bin/make/lst.h |   3 ++-
 3 files changed, 32 insertions(+), 9 deletions(-)

diffs (114 lines):

diff -r 1646641c0500 -r 400fca9ae5b3 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Sat Aug 22 09:16:08 2020 +0000
+++ b/usr.bin/make/dir.c        Sat Aug 22 09:40:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.98 2020/08/22 09:03:53 rillig Exp $  */
+/*     $NetBSD: dir.c,v 1.99 2020/08/22 09:40:18 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.98 2020/08/22 09:03:53 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.99 2020/08/22 09:40:18 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.98 2020/08/22 09:03:53 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.99 2020/08/22 09:40:18 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -768,7 +768,7 @@
            Dir_Expand(file, path, expansions);
            free(file);
        } else {
-           (void)Lst_AtEnd(expansions, file);
+           Lst_AppendS(expansions, file);
        }
 
        piece = piece_end + 1;  /* skip over the comma or closing brace */
diff -r 1646641c0500 -r 400fca9ae5b3 usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Sat Aug 22 09:16:08 2020 +0000
+++ b/usr.bin/make/lst.c        Sat Aug 22 09:40:18 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.20 2020/08/22 07:26:34 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.21 2020/08/22 09:40:18 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.20 2020/08/22 07:26:34 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.21 2020/08/22 09:40:18 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.20 2020/08/22 07:26:34 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.21 2020/08/22 09:40:18 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -64,8 +64,8 @@
     LstNode last;              /* last node in list */
 
     /* fields for sequential access */
+    Boolean isOpen;            /* true if list has been Lst_Open'ed */
     Where lastAccess;          /* Where in the list the last access was */
-    Boolean isOpen;            /* true if list has been Lst_Open'ed */
     LstNode curr;              /* current node, if open. NULL if
                                 * *just* opened */
     LstNode prev;              /* Previous node, if open. Used by Lst_Remove */
@@ -280,6 +280,28 @@
     return Lst_InsertAfter(list, end, datum);
 }
 
+/* Add a piece of data at the end of the given list. */
+void
+Lst_AppendS(Lst list, void *datum)
+{
+    LstNode node;
+
+    assert(LstIsValid(list));
+    assert(datum != NULL);
+
+    node = LstNodeNew(datum);
+    node->prev = list->last;
+    node->next = NULL;
+
+    if (list->last == NULL) {
+       list->first = node;
+       list->last = node;
+    } else {
+       list->last->next = node;
+       list->last = node;
+    }
+}
+
 /* Remove the given node from the given list.
  * The datum stored in the node must be freed by the caller, if necessary. */
 void
diff -r 1646641c0500 -r 400fca9ae5b3 usr.bin/make/lst.h
--- a/usr.bin/make/lst.h        Sat Aug 22 09:16:08 2020 +0000
+++ b/usr.bin/make/lst.h        Sat Aug 22 09:40:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lst.h,v 1.27 2020/08/21 07:00:32 rillig Exp $  */
+/*     $NetBSD: lst.h,v 1.28 2020/08/22 09:40:18 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -121,6 +121,7 @@
 ReturnStatus   Lst_AtFront(Lst, void *);
 /* Place an element at the end of a lst. */
 ReturnStatus   Lst_AtEnd(Lst, void *);
+void           Lst_AppendS(Lst, void *);
 /* Remove an element */
 void           Lst_RemoveS(Lst, LstNode);
 /* Replace a node with a new value */



Home | Main Index | Thread Index | Old Index