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): extract creation of a list node into a...



details:   https://anonhg.NetBSD.org/src/rev/f499795b5235
branches:  trunk
changeset: 975082:f499795b5235
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Aug 21 05:19:48 2020 +0000

description:
make(1): extract creation of a list node into a separate function

diffstat:

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

diffs (85 lines):

diff -r e590b13a792b -r f499795b5235 usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Fri Aug 21 04:57:56 2020 +0000
+++ b/usr.bin/make/lst.c        Fri Aug 21 05:19:48 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.11 2020/08/21 04:57:56 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.12 2020/08/21 05:19:48 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -38,11 +38,11 @@
 #include "make_malloc.h"
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: lst.c,v 1.11 2020/08/21 04:57:56 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.12 2020/08/21 05:19:48 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.11 2020/08/21 04:57:56 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.12 2020/08/21 05:19:48 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -94,6 +94,18 @@
     return ln != NULL;
 }
 
+static LstNode
+LstNodeNew(void *datum)
+{
+    ListNode ln = bmake_malloc(sizeof *ln);
+    /* prevPtr will be initialized by the calling code. */
+    /* nextPtr will be initialized by the calling code. */
+    ln->useCount = 0;
+    ln->deleted = FALSE;
+    ln->datum = datum;
+    return ln;
+}
+
 /*
  * LstIsEmpty (l) --
  *     TRUE if the list l is empty.
@@ -260,11 +272,7 @@
     }
 
     ok:
-    nLNode = bmake_malloc(sizeof *nLNode);
-
-    nLNode->datum = d;
-    nLNode->useCount = 0;
-    nLNode->deleted = FALSE;
+    nLNode = LstNodeNew(d);
 
     if (ln == NULL) {
        nLNode->prevPtr = nLNode->nextPtr = NULL;
@@ -326,10 +334,7 @@
     list = l;
     lNode = ln;
 
-    nLNode = bmake_malloc(sizeof *nLNode);
-    nLNode->datum = d;
-    nLNode->useCount = 0;
-    nLNode->deleted = FALSE;
+    nLNode = LstNodeNew(d);
 
     if (lNode == NULL) {
        nLNode->nextPtr = nLNode->prevPtr = NULL;
@@ -836,16 +841,13 @@
             ln != NULL;
             ln = ln->nextPtr)
        {
-           nln = bmake_malloc(sizeof *nln);
-           nln->datum = ln->datum;
+           nln = LstNodeNew(ln->datum);
            if (last != NULL) {
                last->nextPtr = nln;
            } else {
                list1->firstPtr = nln;
            }
            nln->prevPtr = last;
-           nln->useCount = 0;
-           nln->deleted = FALSE;
            last = nln;
        }
 



Home | Main Index | Thread Index | Old Index