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): reduce pointer indirection for archives
details: https://anonhg.NetBSD.org/src/rev/58dd5b849ae8
branches: trunk
changeset: 946472:58dd5b849ae8
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Nov 28 19:26:10 2020 +0000
description:
make(1): reduce pointer indirection for archives
diffstat:
usr.bin/make/arch.c | 14 +++++++-------
usr.bin/make/lst.c | 25 +++++++++++++++----------
usr.bin/make/lst.h | 4 +++-
3 files changed, 25 insertions(+), 18 deletions(-)
diffs (131 lines):
diff -r 157cbb48918a -r 58dd5b849ae8 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c Sat Nov 28 19:22:32 2020 +0000
+++ b/usr.bin/make/arch.c Sat Nov 28 19:26:10 2020 +0000
@@ -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 @@
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 @@
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 @@
void
Arch_Init(void)
{
- archives = Lst_New();
+ Lst_Init(&archives);
}
/* Clean up the archives module. */
@@ -1071,7 +1071,7 @@
Arch_End(void)
{
#ifdef CLEANUP
- Lst_Destroy(archives, ArchFree);
+ Lst_DoneCall(&archives, ArchFree);
#endif
}
diff -r 157cbb48918a -r 58dd5b849ae8 usr.bin/make/lst.c
--- a/usr.bin/make/lst.c Sat Nov 28 19:22:32 2020 +0000
+++ b/usr.bin/make/lst.c Sat Nov 28 19:26:10 2020 +0000
@@ -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 @@
}
}
+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 @@
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);
}
diff -r 157cbb48918a -r 58dd5b849ae8 usr.bin/make/lst.h
--- a/usr.bin/make/lst.h Sat Nov 28 19:22:32 2020 +0000
+++ b/usr.bin/make/lst.h Sat Nov 28 19:26:10 2020 +0000
@@ -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 @@
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. */
Home |
Main Index |
Thread Index |
Old Index