Module Name: src
Committed By: rillig
Date: Mon Nov 23 18:24:05 UTC 2020
Modified Files:
src/usr.bin/make: dir.c dir.h hash.h
Log Message:
make(1): migrate CachedDir.files from HashTable to HashSet
To generate a diff of this commit:
cvs rdiff -u -r1.210 -r1.211 src/usr.bin/make/dir.c
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/make/dir.h
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/make/hash.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/dir.c
diff -u src/usr.bin/make/dir.c:1.210 src/usr.bin/make/dir.c:1.211
--- src/usr.bin/make/dir.c:1.210 Sat Nov 14 21:29:44 2020
+++ src/usr.bin/make/dir.c Mon Nov 23 18:24:05 2020
@@ -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, Cache
/* 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 *ba
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
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
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
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);
}
Index: src/usr.bin/make/dir.h
diff -u src/usr.bin/make/dir.h:1.34 src/usr.bin/make/dir.h:1.35
--- src/usr.bin/make/dir.h:1.34 Sat Nov 14 19:24:24 2020
+++ src/usr.bin/make/dir.h Mon Nov 23 18:24:05 2020
@@ -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);
Index: src/usr.bin/make/hash.h
diff -u src/usr.bin/make/hash.h:1.35 src/usr.bin/make/hash.h:1.36
--- src/usr.bin/make/hash.h:1.35 Mon Nov 23 18:07:10 2020
+++ src/usr.bin/make/hash.h Mon Nov 23 18:24:05 2020
@@ -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 cha
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 */