Module Name: src Committed By: rillig Date: Mon Nov 23 18:07:10 UTC 2020
Modified Files: src/usr.bin/make: hash.h suff.c Log Message: make(1): add HashSet type This makes the code for handling suffixes simpler since it doesn't need the clumsy API of HashTable_CreateEntry anymore. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/usr.bin/make/hash.h cvs rdiff -u -r1.306 -r1.307 src/usr.bin/make/suff.c 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/hash.h diff -u src/usr.bin/make/hash.h:1.34 src/usr.bin/make/hash.h:1.35 --- src/usr.bin/make/hash.h:1.34 Mon Nov 23 17:59:21 2020 +++ src/usr.bin/make/hash.h Mon Nov 23 18:07:10 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: hash.h,v 1.34 2020/11/23 17:59:21 rillig Exp $ */ +/* $NetBSD: hash.h,v 1.35 2020/11/23 18:07:10 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -103,6 +103,11 @@ typedef struct HashIter { HashEntry *entry; /* Next entry to check in current bucket. */ } HashIter; +/* A set of strings. */ +typedef struct HashSet { + HashTable tbl; +} HashSet; + MAKE_INLINE void * HashEntry_Get(HashEntry *h) { @@ -129,4 +134,31 @@ void HashTable_DebugStats(HashTable *, c void HashIter_Init(HashIter *, HashTable *); HashEntry *HashIter_Next(HashIter *); +MAKE_INLINE void +HashSet_Init(HashSet *set) +{ + HashTable_Init(&set->tbl); +} + +MAKE_INLINE void +HashSet_Done(HashSet *set) +{ + HashTable_Done(&set->tbl); +} + +MAKE_INLINE Boolean +HashSet_Add(HashSet *set, const char *key) +{ + Boolean isNew; + + (void)HashTable_CreateEntry(&set->tbl, key, &isNew); + return isNew; +} + +MAKE_INLINE Boolean +HashSet_Contains(HashSet *set, const char *key) +{ + return HashTable_FindEntry(&set->tbl, key) != NULL; +} + #endif /* MAKE_HASH_H */ Index: src/usr.bin/make/suff.c diff -u src/usr.bin/make/suff.c:1.306 src/usr.bin/make/suff.c:1.307 --- src/usr.bin/make/suff.c:1.306 Mon Nov 23 14:47:12 2020 +++ src/usr.bin/make/suff.c Mon Nov 23 18:07:10 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: suff.c,v 1.306 2020/11/23 14:47:12 rillig Exp $ */ +/* $NetBSD: suff.c,v 1.307 2020/11/23 18:07:10 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -114,7 +114,7 @@ #include "dir.h" /* "@(#)suff.c 8.4 (Berkeley) 3/21/94" */ -MAKE_RCSID("$NetBSD: suff.c,v 1.306 2020/11/23 14:47:12 rillig Exp $"); +MAKE_RCSID("$NetBSD: suff.c,v 1.307 2020/11/23 18:07:10 rillig Exp $"); #define SUFF_DEBUG0(text) DEBUG0(SUFF, text) #define SUFF_DEBUG1(fmt, arg1) DEBUG1(SUFF, fmt, arg1) @@ -1060,9 +1060,9 @@ RemoveCandidate(CandidateList *srcs) static Candidate * FindThem(CandidateList *srcs, CandidateSearcher *cs) { - HashTable seen; + HashSet seen; - HashTable_Init(&seen); + HashSet_Init(&seen); while (!Lst_IsEmpty(srcs)) { Candidate *src = Lst_Dequeue(srcs); @@ -1078,7 +1078,7 @@ FindThem(CandidateList *srcs, CandidateS */ if (Targ_FindNode(src->file) != NULL) { found: - HashTable_Done(&seen); + HashSet_Done(&seen); SUFF_DEBUG0("got it\n"); return src; } @@ -1093,22 +1093,16 @@ FindThem(CandidateList *srcs, CandidateS SUFF_DEBUG0("not there\n"); - { - Boolean isNew; - - HashTable_CreateEntry(&seen, src->file, &isNew); - if (isNew) - CandidateList_AddCandidatesFor(srcs, src); - else { - DEBUG1(SUFF, "FindThem: skipping duplicate \"%s\"\n", - src->file); - } + if (HashSet_Add(&seen, src->file)) + CandidateList_AddCandidatesFor(srcs, src); + else { + SUFF_DEBUG1("FindThem: skipping duplicate \"%s\"\n", src->file); } CandidateSearcher_Add(cs, src); } - HashTable_Done(&seen); + HashSet_Done(&seen); return NULL; }