summaryrefslogtreecommitdiff
path: root/usr.bin/make
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2020-11-23 18:24:05 +0000
committerrillig <rillig@NetBSD.org>2020-11-23 18:24:05 +0000
commitd8b3a2aeb065ebb58fb1d0d7b2a11a6ad0bb84cb (patch)
tree0be91e0d1bab3270c213f5afb11a76a2a191d024 /usr.bin/make
parent1cf1dbcfd733bbc79e3908b1312cb4572dd24255 (diff)
make(1): migrate CachedDir.files from HashTable to HashSet
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/dir.c22
-rw-r--r--usr.bin/make/dir.h5
-rw-r--r--usr.bin/make/hash.h8
3 files changed, 20 insertions, 15 deletions
diff --git a/usr.bin/make/dir.c b/usr.bin/make/dir.c
index 359e61adb66..1952079931a 100644
--- a/usr.bin/make/dir.c
+++ b/usr.bin/make/dir.c
@@ -1,4 +1,4 @@
-/* $NetBSD: dir.c,v 1.210 2020/11/14 21:29:44 rillig Exp $ */
+/* $NetBSD: dir.c,v 1.211 2020/11/23 18:24:05 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.210 2020/11/14 21:29:44 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.211 2020/11/23 18:24:05 rillig Exp $");
#define DIR_DEBUG0(text) DEBUG0(DIR, text)
#define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1)
@@ -379,7 +379,7 @@ Dir_InitDir(const char *cdname)
dotLast->refCount = 1;
dotLast->hits = 0;
dotLast->name = bmake_strdup(".DOTLAST");
- HashTable_Init(&dotLast->files);
+ HashSet_Init(&dotLast->files);
}
/*
@@ -573,7 +573,7 @@ DirMatchFiles(const char *pattern, CachedDir *dir, StringList *expansions)
/* XXX: Iterating over all hash entries is inefficient. If the pattern
* is a plain string without any wildcards, a direct lookup is faster. */
- HashIter_Init(&hi, &dir->files);
+ HashIter_InitSet(&hi, &dir->files);
while (HashIter_Next(&hi) != NULL) {
const char *base = hi.entry->key;
@@ -848,7 +848,7 @@ DirLookup(CachedDir *dir, const char *base)
DIR_DEBUG1(" %s ...\n", dir->name);
- if (HashTable_FindEntry(&dir->files, base) == NULL)
+ if (!HashSet_Contains(&dir->files, base))
return NULL;
file = str_concat3(dir->name, "/", base);
@@ -901,7 +901,7 @@ DirLookupAbs(CachedDir *dir, const char *name, const char *cp)
if (*dnp != '\0' || np != cp - 1)
return NULL;
- if (HashTable_FindEntry(&dir->files, cp) == NULL) {
+ if (!HashSet_Contains(&dir->files, cp)) {
DIR_DEBUG0(" must be here but isn't -- returning\n");
return bmake_strdup(""); /* to terminate the search */
}
@@ -918,14 +918,14 @@ static char *
DirFindDot(const char *name, const char *base)
{
- if (HashTable_FindEntry(&dot->files, base) != NULL) {
+ if (HashSet_Contains(&dot->files, base)) {
DIR_DEBUG0(" in '.'\n");
hits++;
dot->hits++;
return bmake_strdup(name);
}
- if (cur != NULL && HashTable_FindEntry(&cur->files, base) != NULL) {
+ if (cur != NULL && HashSet_Contains(&cur->files, base)) {
DIR_DEBUG1(" in ${.CURDIR} = %s\n", cur->name);
hits++;
cur->hits++;
@@ -1390,7 +1390,7 @@ Dir_AddDir(SearchPath *path, const char *name)
dir->name = bmake_strdup(name);
dir->hits = 0;
dir->refCount = 1;
- HashTable_Init(&dir->files);
+ HashSet_Init(&dir->files);
while ((dp = readdir(d)) != NULL) {
#if defined(sun) && defined(d_ino) /* d_ino is a sunos4 #define for d_fileno */
@@ -1403,7 +1403,7 @@ Dir_AddDir(SearchPath *path, const char *name)
continue;
}
#endif /* sun && d_ino */
- (void)HashTable_CreateEntry(&dir->files, dp->d_name, NULL);
+ (void)HashSet_Add(&dir->files, dp->d_name);
}
(void)closedir(d);
OpenDirs_Add(&openDirs, dir);
@@ -1485,7 +1485,7 @@ Dir_Destroy(void *dirp)
if (dir->refCount == 0) {
OpenDirs_Remove(&openDirs, dir->name);
- HashTable_Done(&dir->files);
+ HashSet_Done(&dir->files);
free(dir->name);
free(dir);
}
diff --git a/usr.bin/make/dir.h b/usr.bin/make/dir.h
index d0badcd1dec..cd13f32b4c9 100644
--- a/usr.bin/make/dir.h
+++ b/usr.bin/make/dir.h
@@ -1,4 +1,4 @@
-/* $NetBSD: dir.h,v 1.34 2020/11/14 19:24:24 rillig Exp $ */
+/* $NetBSD: dir.h,v 1.35 2020/11/23 18:24:05 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -87,8 +87,7 @@ typedef struct CachedDir {
int refCount; /* Number of SearchPaths with this directory */
int hits; /* The number of times a file in this
* directory has been found */
- HashTable files; /* Hash set of files in directory;
- * all values are NULL. */
+ HashSet files; /* The files in the directory. */
} CachedDir;
void Dir_Init(void);
diff --git a/usr.bin/make/hash.h b/usr.bin/make/hash.h
index fb5e7cf29a9..a7a4844c695 100644
--- a/usr.bin/make/hash.h
+++ b/usr.bin/make/hash.h
@@ -1,4 +1,4 @@
-/* $NetBSD: hash.h,v 1.35 2020/11/23 18:07:10 rillig Exp $ */
+/* $NetBSD: hash.h,v 1.36 2020/11/23 18:24:05 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -161,4 +161,10 @@ HashSet_Contains(HashSet *set, const char *key)
return HashTable_FindEntry(&set->tbl, key) != NULL;
}
+MAKE_INLINE void
+HashIter_InitSet(HashIter *hi, HashSet *set)
+{
+ HashIter_Init(hi, &set->tbl);
+}
+
#endif /* MAKE_HASH_H */