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): replace a few HashTable_CreateEntry wi...
details: https://anonhg.NetBSD.org/src/rev/1233fec46cb2
branches: trunk
changeset: 1016296:1233fec46cb2
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Nov 14 21:29:44 2020 +0000
description:
make(1): replace a few HashTable_CreateEntry with HashTable_Set
Instead of HashTable_CreateEntry and HashEntry_Set, several places just
need the HashEntry for storing a value in it. This makes the calling
code simpler to understand.
These parts of the code are already hard enough to understand since they
are about memory management and aliasing. Having a too detailed API for
the HashTable only distracts from these topics.
diffstat:
usr.bin/make/arch.c | 11 +++++------
usr.bin/make/dir.c | 26 ++++++++------------------
usr.bin/make/hash.c | 12 ++++++++++--
usr.bin/make/hash.h | 3 ++-
usr.bin/make/var.c | 11 +++++------
5 files changed, 30 insertions(+), 33 deletions(-)
diffs (192 lines):
diff -r 1856bc10f0dd -r 1233fec46cb2 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c Sat Nov 14 21:24:03 2020 +0000
+++ b/usr.bin/make/arch.c Sat Nov 14 21:29:44 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: arch.c,v 1.176 2020/11/14 06:10:28 rillig Exp $ */
+/* $NetBSD: arch.c,v 1.177 2020/11/14 21:29:44 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -125,7 +125,7 @@
#include "config.h"
/* "@(#)arch.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: arch.c,v 1.176 2020/11/14 06:10:28 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.177 2020/11/14 21:29:44 rillig Exp $");
typedef struct List ArchList;
typedef struct ListNode ArchListNode;
@@ -557,10 +557,9 @@
#endif
{
- HashEntry *he;
- he = HashTable_CreateEntry(&ar->members, memName, NULL);
- HashEntry_Set(he, bmake_malloc(sizeof arh));
- memcpy(HashEntry_Get(he), &arh, sizeof arh);
+ struct ar_hdr *cached_hdr = bmake_malloc(sizeof *cached_hdr);
+ memcpy(cached_hdr, &arh, sizeof arh);
+ HashTable_Set(&ar->members, memName, cached_hdr);
}
if (fseek(arch, ((long)size + 1) & ~1, SEEK_CUR) != 0)
diff -r 1856bc10f0dd -r 1233fec46cb2 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c Sat Nov 14 21:24:03 2020 +0000
+++ b/usr.bin/make/dir.c Sat Nov 14 21:29:44 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dir.c,v 1.209 2020/11/14 19:36:31 rillig Exp $ */
+/* $NetBSD: dir.c,v 1.210 2020/11/14 21:29:44 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -134,7 +134,7 @@
#include "job.h"
/* "@(#)dir.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: dir.c,v 1.209 2020/11/14 19:36:31 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.210 2020/11/14 21:29:44 rillig Exp $");
#define DIR_DEBUG0(text) DEBUG0(DIR, text)
#define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1)
@@ -253,12 +253,10 @@
static void
OpenDirs_Add(OpenDirs *odirs, CachedDir *cdir)
{
- HashEntry *he = HashTable_FindEntry(&odirs->table, cdir->name);
- if (he != NULL)
+ if (HashTable_FindEntry(&odirs->table, cdir->name) != NULL)
return;
- he = HashTable_CreateEntry(&odirs->table, cdir->name, NULL);
Lst_Append(odirs->list, cdir);
- HashEntry_Set(he, odirs->list->last);
+ HashTable_Set(&odirs->table, cdir->name, odirs->list->last);
}
static void
@@ -313,7 +311,6 @@
CachedStatsFlags flags)
{
HashTable *tbl = flags & CST_LSTAT ? &lmtimes : &mtimes;
- HashEntry *entry;
struct stat sys_st;
struct cached_stat *cst;
int rc;
@@ -321,11 +318,8 @@
if (pathname == NULL || pathname[0] == '\0')
return -1; /* This can happen in meta mode. */
- entry = HashTable_FindEntry(tbl, pathname);
-
- if (entry != NULL && !(flags & CST_UPDATE)) {
- cst = HashEntry_Get(entry);
-
+ cst = HashTable_FindValue(tbl, pathname);
+ if (cst != NULL && !(flags & CST_UPDATE)) {
*out_cst = *cst;
DIR_DEBUG2("Using cached time %s for %s\n",
Targ_FmtTime(cst->cst_mtime), pathname);
@@ -339,13 +333,9 @@
if (sys_st.st_mtime == 0)
sys_st.st_mtime = 1; /* avoid confusion with missing file */
- if (entry != NULL)
- cst = entry->value;
- else {
- entry = HashTable_CreateEntry(tbl, pathname, NULL);
+ if (cst == NULL) {
cst = bmake_malloc(sizeof *cst);
- memset(cst, 0, sizeof *cst);
- HashEntry_Set(entry, cst);
+ HashTable_Set(tbl, pathname, cst);
}
cst->cst_mtime = sys_st.st_mtime;
diff -r 1856bc10f0dd -r 1233fec46cb2 usr.bin/make/hash.c
--- a/usr.bin/make/hash.c Sat Nov 14 21:24:03 2020 +0000
+++ b/usr.bin/make/hash.c Sat Nov 14 21:29:44 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hash.c,v 1.56 2020/11/05 17:27:16 rillig Exp $ */
+/* $NetBSD: hash.c,v 1.57 2020/11/14 21:29:44 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -74,7 +74,7 @@
#include "make.h"
/* "@(#)hash.c 8.1 (Berkeley) 6/6/93" */
-MAKE_RCSID("$NetBSD: hash.c,v 1.56 2020/11/05 17:27:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: hash.c,v 1.57 2020/11/14 21:29:44 rillig Exp $");
/*
* The ratio of # entries to # buckets at which we rebuild the table to
@@ -253,6 +253,14 @@
return he;
}
+HashEntry *
+HashTable_Set(HashTable *t, const char *key, void *value)
+{
+ HashEntry *he = HashTable_CreateEntry(t, key, NULL);
+ HashEntry_Set(he, value);
+ return he;
+}
+
/* Delete the entry from the table and free the associated memory. */
void
HashTable_DeleteEntry(HashTable *t, HashEntry *he)
diff -r 1856bc10f0dd -r 1233fec46cb2 usr.bin/make/hash.h
--- a/usr.bin/make/hash.h Sat Nov 14 21:24:03 2020 +0000
+++ b/usr.bin/make/hash.h Sat Nov 14 21:29:44 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hash.h,v 1.32 2020/11/10 00:32:12 rillig Exp $ */
+/* $NetBSD: hash.h,v 1.33 2020/11/14 21:29:44 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -122,6 +122,7 @@
unsigned int Hash_Hash(const char *);
void *HashTable_FindValueHash(HashTable *, const char *, unsigned int);
HashEntry *HashTable_CreateEntry(HashTable *, const char *, Boolean *);
+HashEntry *HashTable_Set(HashTable *, const char *, void *);
void HashTable_DeleteEntry(HashTable *, HashEntry *);
void HashTable_DebugStats(HashTable *, const char *);
diff -r 1856bc10f0dd -r 1233fec46cb2 usr.bin/make/var.c
--- a/usr.bin/make/var.c Sat Nov 14 21:24:03 2020 +0000
+++ b/usr.bin/make/var.c Sat Nov 14 21:29:44 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.684 2020/11/10 00:32:12 rillig Exp $ */
+/* $NetBSD: var.c,v 1.685 2020/11/14 21:29:44 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -130,7 +130,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.684 2020/11/10 00:32:12 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.685 2020/11/14 21:29:44 rillig Exp $");
#define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
#define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
@@ -953,8 +953,6 @@
ctxt->name, name, Buf_GetAll(&v->val, NULL));
if (v->flags & VAR_FROM_ENV) {
- HashEntry *h;
-
/*
* If the original variable came from the environment, we
* have to install it in the global context (we could place
@@ -962,8 +960,9 @@
* export other variables...)
*/
v->flags &= ~(unsigned)VAR_FROM_ENV;
- h = HashTable_CreateEntry(&ctxt->context, name, NULL);
- HashEntry_Set(h, v);
+ /* This is the only place where a variable is created whose
+ * v->name is not the same as ctxt->context->key. */
+ HashTable_Set(&ctxt->context, name, v);
}
}
free(name_freeIt);
Home |
Main Index |
Thread Index |
Old Index