Module Name: src
Committed By: rillig
Date: Sat Nov 28 19:26:10 UTC 2020
Modified Files:
src/usr.bin/make: arch.c lst.c lst.h
Log Message:
make(1): reduce pointer indirection for archives
To generate a diff of this commit:
cvs rdiff -u -r1.179 -r1.180 src/usr.bin/make/arch.c
cvs rdiff -u -r1.95 -r1.96 src/usr.bin/make/lst.c
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/make/lst.h
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/arch.c
diff -u src/usr.bin/make/arch.c:1.179 src/usr.bin/make/arch.c:1.180
--- src/usr.bin/make/arch.c:1.179 Sat Nov 28 19:12:28 2020
+++ src/usr.bin/make/arch.c Sat Nov 28 19:26:10 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: arch.c,v 1.179 2020/11/28 19:12:28 rillig Exp $ */
+/* $NetBSD: arch.c,v 1.180 2020/11/28 19:26:10 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -125,12 +125,12 @@
#include "config.h"
/* "@(#)arch.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: arch.c,v 1.179 2020/11/28 19:12:28 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.180 2020/11/28 19:26:10 rillig Exp $");
typedef struct List ArchList;
typedef struct ListNode ArchListNode;
-static ArchList *archives; /* The archives we've already examined */
+static ArchList archives; /* The archives we've already examined */
typedef struct Arch {
char *name; /* Name of archive */
@@ -426,7 +426,7 @@ ArchStatMember(const char *archive, cons
if (lastSlash != NULL)
member = lastSlash + 1;
- for (ln = archives->first; ln != NULL; ln = ln->next) {
+ for (ln = archives.first; ln != NULL; ln = ln->next) {
const Arch *a = ln->datum;
if (strcmp(a->name, archive) == 0)
break;
@@ -579,7 +579,7 @@ ArchStatMember(const char *archive, cons
fclose(arch);
- Lst_Append(archives, ar);
+ Lst_Append(&archives, ar);
/*
* Now that the archive has been read and cached, we can look into
@@ -1063,7 +1063,7 @@ Arch_LibOODate(GNode *gn)
void
Arch_Init(void)
{
- archives = Lst_New();
+ Lst_Init(&archives);
}
/* Clean up the archives module. */
@@ -1071,7 +1071,7 @@ void
Arch_End(void)
{
#ifdef CLEANUP
- Lst_Destroy(archives, ArchFree);
+ Lst_DoneCall(&archives, ArchFree);
#endif
}
Index: src/usr.bin/make/lst.c
diff -u src/usr.bin/make/lst.c:1.95 src/usr.bin/make/lst.c:1.96
--- src/usr.bin/make/lst.c:1.95 Sat Nov 28 18:55:52 2020
+++ src/usr.bin/make/lst.c Sat Nov 28 19:26:10 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.95 2020/11/28 18:55:52 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.96 2020/11/28 19:26:10 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -34,7 +34,7 @@
#include "make.h"
-MAKE_RCSID("$NetBSD: lst.c,v 1.95 2020/11/28 18:55:52 rillig Exp $");
+MAKE_RCSID("$NetBSD: lst.c,v 1.96 2020/11/28 19:26:10 rillig Exp $");
static ListNode *
LstNodeNew(ListNode *prev, ListNode *next, void *datum)
@@ -68,6 +68,18 @@ Lst_Done(List *list)
}
}
+void
+Lst_DoneCall(List *list, LstFreeProc freeProc)
+{
+ ListNode *ln, *next;
+
+ for (ln = list->first; ln != NULL; ln = next) {
+ next = ln->next;
+ freeProc(ln->datum);
+ free(ln);
+ }
+}
+
/* Free a list and all its nodes. The node data are not freed though. */
void
Lst_Free(List *list)
@@ -82,14 +94,7 @@ Lst_Free(List *list)
void
Lst_Destroy(List *list, LstFreeProc freeProc)
{
- ListNode *ln, *next;
-
- for (ln = list->first; ln != NULL; ln = next) {
- next = ln->next;
- freeProc(ln->datum);
- free(ln);
- }
-
+ Lst_DoneCall(list, freeProc);
free(list);
}
Index: src/usr.bin/make/lst.h
diff -u src/usr.bin/make/lst.h:1.88 src/usr.bin/make/lst.h:1.89
--- src/usr.bin/make/lst.h:1.88 Sat Nov 28 18:55:52 2020
+++ src/usr.bin/make/lst.h Sat Nov 28 19:26:10 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.h,v 1.88 2020/11/28 18:55:52 rillig Exp $ */
+/* $NetBSD: lst.h,v 1.89 2020/11/28 19:26:10 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -111,6 +111,8 @@ typedef void LstFreeProc(void *);
List *Lst_New(void);
/* Free the list nodes, but not the list itself. */
void Lst_Done(List *);
+/* Free the list nodes, freeing the node data using the given function. */
+void Lst_DoneCall(List *, LstFreeProc);
/* Free the list, leaving the node data unmodified. */
void Lst_Free(List *);
/* Free the list, freeing the node data using the given function. */