make: clean up API for iterating over hash tables
This commit is contained in:
parent
9017c2c0e2
commit
2864ddb2e9
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: arch.c,v 1.217 2024/04/27 20:41:32 rillig Exp $ */
|
||||
/* $NetBSD: arch.c,v 1.218 2024/05/31 05:50:11 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1993
|
||||
|
@ -126,7 +126,7 @@
|
|||
#include "config.h"
|
||||
|
||||
/* "@(#)arch.c 8.2 (Berkeley) 1/2/94" */
|
||||
MAKE_RCSID("$NetBSD: arch.c,v 1.217 2024/04/27 20:41:32 rillig Exp $");
|
||||
MAKE_RCSID("$NetBSD: arch.c,v 1.218 2024/05/31 05:50:11 rillig Exp $");
|
||||
|
||||
typedef struct List ArchList;
|
||||
typedef struct ListNode ArchListNode;
|
||||
|
@ -156,7 +156,7 @@ ArchFree(Arch *a)
|
|||
HashIter hi;
|
||||
|
||||
HashIter_Init(&hi, &a->members);
|
||||
while (HashIter_Next(&hi) != NULL)
|
||||
while (HashIter_Next(&hi))
|
||||
free(hi.entry->value);
|
||||
|
||||
free(a->name);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: dir.c,v 1.293 2024/05/25 08:03:19 rillig Exp $ */
|
||||
/* $NetBSD: dir.c,v 1.294 2024/05/31 05:50:11 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||
|
@ -132,7 +132,7 @@
|
|||
#include "job.h"
|
||||
|
||||
/* "@(#)dir.c 8.2 (Berkeley) 1/2/94" */
|
||||
MAKE_RCSID("$NetBSD: dir.c,v 1.293 2024/05/25 08:03:19 rillig Exp $");
|
||||
MAKE_RCSID("$NetBSD: dir.c,v 1.294 2024/05/31 05:50:11 rillig Exp $");
|
||||
|
||||
/*
|
||||
* A search path is a list of CachedDir structures. A CachedDir has in it the
|
||||
|
@ -507,7 +507,7 @@ FreeCachedTable(HashTable *tbl)
|
|||
{
|
||||
HashIter hi;
|
||||
HashIter_Init(&hi, tbl);
|
||||
while (HashIter_Next(&hi) != NULL)
|
||||
while (HashIter_Next(&hi))
|
||||
free(hi.entry->value);
|
||||
HashTable_Done(tbl);
|
||||
}
|
||||
|
@ -656,7 +656,7 @@ DirMatchFiles(const char *pattern, CachedDir *dir, StringList *expansions)
|
|||
*/
|
||||
|
||||
HashIter_InitSet(&hi, &dir->files);
|
||||
while (HashIter_Next(&hi) != NULL) {
|
||||
while (HashIter_Next(&hi)) {
|
||||
const char *base = hi.entry->key;
|
||||
StrMatchResult res = Str_Match(base, pattern);
|
||||
/* TODO: handle errors from res.error */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: hash.c,v 1.75 2024/05/24 22:54:07 rillig Exp $ */
|
||||
/* $NetBSD: hash.c,v 1.76 2024/05/31 05:50:11 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.75 2024/05/24 22:54:07 rillig Exp $");
|
||||
MAKE_RCSID("$NetBSD: hash.c,v 1.76 2024/05/31 05:50:11 rillig Exp $");
|
||||
|
||||
/*
|
||||
* The ratio of # entries to # buckets at which we rebuild the table to
|
||||
|
@ -300,7 +300,7 @@ HashTable_DeleteEntry(HashTable *t, HashEntry *he)
|
|||
* Return the next entry in the hash table, or NULL if the end of the table
|
||||
* is reached.
|
||||
*/
|
||||
HashEntry *
|
||||
bool
|
||||
HashIter_Next(HashIter *hi)
|
||||
{
|
||||
HashTable *t = hi->table;
|
||||
|
@ -313,11 +313,11 @@ HashIter_Next(HashIter *hi)
|
|||
|
||||
while (he == NULL) { /* find the next nonempty chain */
|
||||
if (hi->nextBucket >= bucketsSize)
|
||||
return NULL;
|
||||
return false;
|
||||
he = buckets[hi->nextBucket++];
|
||||
}
|
||||
hi->entry = he;
|
||||
return he;
|
||||
return he != NULL;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: hash.h,v 1.48 2023/12/19 19:33:39 rillig Exp $ */
|
||||
/* $NetBSD: hash.h,v 1.49 2024/05/31 05:50:11 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||
|
@ -140,7 +140,7 @@ void HashTable_Set(HashTable *, const char *, void *);
|
|||
void HashTable_DeleteEntry(HashTable *, HashEntry *);
|
||||
void HashTable_DebugStats(HashTable *, const char *);
|
||||
|
||||
HashEntry *HashIter_Next(HashIter *);
|
||||
bool HashIter_Next(HashIter *);
|
||||
|
||||
MAKE_INLINE void
|
||||
HashSet_Init(HashSet *set)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: main.c,v 1.618 2024/05/28 19:09:04 sjg Exp $ */
|
||||
/* $NetBSD: main.c,v 1.619 2024/05/31 05:50:11 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1993
|
||||
|
@ -111,7 +111,7 @@
|
|||
#include "trace.h"
|
||||
|
||||
/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
|
||||
MAKE_RCSID("$NetBSD: main.c,v 1.618 2024/05/28 19:09:04 sjg Exp $");
|
||||
MAKE_RCSID("$NetBSD: main.c,v 1.619 2024/05/31 05:50:11 rillig Exp $");
|
||||
#if defined(MAKE_NATIVE)
|
||||
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
|
||||
"The Regents of the University of California. "
|
||||
|
@ -1970,13 +1970,13 @@ execDie(const char *af, const char *av)
|
|||
static void
|
||||
purge_relative_cached_realpaths(void)
|
||||
{
|
||||
HashEntry *he, *next;
|
||||
HashIter hi;
|
||||
|
||||
HashIter_Init(&hi, &cached_realpaths);
|
||||
he = HashIter_Next(&hi);
|
||||
while (he != NULL) {
|
||||
next = HashIter_Next(&hi);
|
||||
HashIter_Next(&hi);
|
||||
while (hi.entry != NULL) {
|
||||
HashEntry *he = hi.entry;
|
||||
HashIter_Next(&hi);
|
||||
if (he->key[0] != '/') {
|
||||
DEBUG1(DIR, "cached_realpath: purging %s\n", he->key);
|
||||
HashTable_DeleteEntry(&cached_realpaths, he);
|
||||
|
@ -1985,7 +1985,6 @@ purge_relative_cached_realpaths(void)
|
|||
* free them or document why they cannot be freed.
|
||||
*/
|
||||
}
|
||||
he = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: parse.c,v 1.727 2024/05/25 22:08:35 rillig Exp $ */
|
||||
/* $NetBSD: parse.c,v 1.728 2024/05/31 05:50:11 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1993
|
||||
|
@ -105,7 +105,7 @@
|
|||
#include "pathnames.h"
|
||||
|
||||
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
|
||||
MAKE_RCSID("$NetBSD: parse.c,v 1.727 2024/05/25 22:08:35 rillig Exp $");
|
||||
MAKE_RCSID("$NetBSD: parse.c,v 1.728 2024/05/31 05:50:11 rillig Exp $");
|
||||
|
||||
/* Detects a multiple-inclusion guard in a makefile. */
|
||||
typedef enum {
|
||||
|
@ -2985,7 +2985,7 @@ Parse_End(void)
|
|||
assert(includes.len == 0);
|
||||
Vector_Done(&includes);
|
||||
HashIter_Init(&hi, &guards);
|
||||
while (HashIter_Next(&hi) != NULL) {
|
||||
while (HashIter_Next(&hi)) {
|
||||
Guard *guard = hi.entry->value;
|
||||
free(guard->name);
|
||||
free(guard);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: var.c,v 1.1113 2024/05/30 21:50:34 rillig Exp $ */
|
||||
/* $NetBSD: var.c,v 1.1114 2024/05/31 05:50:11 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1993
|
||||
|
@ -132,7 +132,7 @@
|
|||
#include "metachar.h"
|
||||
|
||||
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
|
||||
MAKE_RCSID("$NetBSD: var.c,v 1.1113 2024/05/30 21:50:34 rillig Exp $");
|
||||
MAKE_RCSID("$NetBSD: var.c,v 1.1114 2024/05/31 05:50:11 rillig Exp $");
|
||||
|
||||
/*
|
||||
* Variables are defined using one of the VAR=value assignments. Their
|
||||
|
@ -588,7 +588,7 @@ Var_DeleteAll(GNode *scope)
|
|||
{
|
||||
HashIter hi;
|
||||
HashIter_Init(&hi, &scope->vars);
|
||||
while (HashIter_Next(&hi) != NULL) {
|
||||
while (HashIter_Next(&hi)) {
|
||||
Var *v = hi.entry->value;
|
||||
Buf_Done(&v->val);
|
||||
free(v);
|
||||
|
@ -781,7 +781,7 @@ Var_ReexportVars(GNode *scope)
|
|||
|
||||
/* Ouch! Exporting all variables at once is crazy. */
|
||||
HashIter_Init(&hi, &SCOPE_GLOBAL->vars);
|
||||
while (HashIter_Next(&hi) != NULL) {
|
||||
while (HashIter_Next(&hi)) {
|
||||
Var *var = hi.entry->value;
|
||||
ExportVar(var->name.str, scope, VEM_ENV);
|
||||
}
|
||||
|
@ -4805,7 +4805,7 @@ Var_Dump(GNode *scope)
|
|||
Vector_Init(&vec, sizeof(const char *));
|
||||
|
||||
HashIter_Init(&hi, &scope->vars);
|
||||
while (HashIter_Next(&hi) != NULL)
|
||||
while (HashIter_Next(&hi))
|
||||
*(const char **)Vector_Push(&vec) = hi.entry->key;
|
||||
varnames = vec.items;
|
||||
|
||||
|
|
Loading…
Reference in New Issue