Module Name: src
Committed By: rillig
Date: Fri Aug 21 05:19:48 UTC 2020
Modified Files:
src/usr.bin/make: lst.c
Log Message:
make(1): extract creation of a list node into a separate function
To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/make/lst.c
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.11 src/usr.bin/make/lst.c:1.12
--- src/usr.bin/make/lst.c:1.11 Fri Aug 21 04:57:56 2020
+++ src/usr.bin/make/lst.c Fri Aug 21 05:19:48 2020
@@ -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 @@ LstNodeValid(LstNode ln)
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 @@ Lst_InsertBefore(Lst l, LstNode ln, void
}
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 @@ Lst_InsertAfter(Lst l, LstNode ln, void
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 @@ Lst_Concat(Lst l1, Lst l2, int flags)
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;
}