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): clean up code in lst.c



details:   https://anonhg.NetBSD.org/src/rev/9d0465a23c0e
branches:  trunk
changeset: 977448:9d0465a23c0e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 24 09:03:54 2020 +0000

description:
make(1): clean up code in lst.c

diffstat:

 usr.bin/make/lst.c |  56 +++++++++++++++++------------------------------------
 1 files changed, 18 insertions(+), 38 deletions(-)

diffs (136 lines):

diff -r 7edbcca1787d -r 9d0465a23c0e usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Sat Oct 24 09:01:56 2020 +0000
+++ b/usr.bin/make/lst.c        Sat Oct 24 09:03:54 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.84 2020/10/24 08:56:27 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.85 2020/10/24 09:03:54 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -34,7 +34,7 @@
 
 #include "make.h"
 
-MAKE_RCSID("$NetBSD: lst.c,v 1.84 2020/10/24 08:56:27 rillig Exp $");
+MAKE_RCSID("$NetBSD: lst.c,v 1.85 2020/10/24 09:03:54 rillig Exp $");
 
 static ListNode *
 LstNodeNew(ListNode *prev, ListNode *next, void *datum)
@@ -46,12 +46,6 @@
     return node;
 }
 
-static Boolean
-LstIsEmpty(List *list)
-{
-    return list->first == NULL;
-}
-
 /* Create and initialize a new, empty list. */
 List *
 Lst_New(void)
@@ -126,19 +120,16 @@
 {
     ListNode *newNode;
 
-    assert(!LstIsEmpty(list));
     assert(datum != NULL);
 
     newNode = LstNodeNew(node->prev, node, datum);
 
-    if (node->prev != NULL) {
+    if (node->prev != NULL)
        node->prev->next = newNode;
-    }
     node->prev = newNode;
 
-    if (node == list->first) {
+    if (node == list->first)
        list->first = newNode;
-    }
 }
 
 /* Add a piece of data at the start of the given list. */
@@ -184,26 +175,17 @@
 void
 Lst_Remove(List *list, ListNode *node)
 {
-    /*
-     * unlink it from the list
-     */
-    if (node->next != NULL) {
+    /* unlink it from its neighbors */
+    if (node->next != NULL)
        node->next->prev = node->prev;
-    }
-    if (node->prev != NULL) {
+    if (node->prev != NULL)
        node->prev->next = node->next;
-    }
 
-    /*
-     * if either the first or last of the list point to this node,
-     * adjust them accordingly
-     */
-    if (list->first == node) {
+    /* unlink it from the list */
+    if (list->first == node)
        list->first = node->next;
-    }
-    if (list->last == node) {
+    if (list->last == node)
        list->last = node->prev;
-    }
 }
 
 /* Replace the datum in the given node with the new datum. */
@@ -241,17 +223,17 @@
  *
  * The start node may be NULL, in which case nothing is found. */
 ListNode *
-Lst_FindFrom(List *list, ListNode *node, LstFindProc match, const void *matchArgs)
+Lst_FindFrom(List *list, ListNode *node,
+            LstFindProc match, const void *matchArgs)
 {
     ListNode *tln;
 
     assert(list != NULL);
     assert(match != NULL);
 
-    for (tln = node; tln != NULL; tln = tln->next) {
+    for (tln = node; tln != NULL; tln = tln->next)
        if (match(tln->datum, matchArgs))
            return tln;
-    }
 
     return NULL;
 }
@@ -264,11 +246,9 @@
 
     assert(datum != NULL);
 
-    for (node = list->first; node != NULL; node = node->next) {
-       if (node->datum == datum) {
+    for (node = list->first; node != NULL; node = node->next)
+       if (node->datum == datum)
            return node;
-       }
-    }
 
     return NULL;
 }
@@ -294,11 +274,11 @@
 {
     if (list2->first != NULL) {
        list2->first->prev = list1->last;
-       if (list1->last != NULL) {
+       if (list1->last != NULL)
            list1->last->next = list2->first;
-       } else {
+       else
            list1->first = list2->first;
-       }
+
        list1->last = list2->last;
     }
     free(list2);



Home | Main Index | Thread Index | Old Index