hashmap: use *_entry APIs for iteration

Inspired by list_for_each_entry in the Linux kernel.
Once again, these are somewhat compromised usability-wise
by compilers lacking __typeof__ support.

Signed-off-by: Eric Wong <e@80x24.org>
Reviewed-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Eric Wong
2019-10-06 23:30:38 +00:00
committed by Junio C Hamano
parent 939af16eac
commit 87571c3f71
13 changed files with 70 additions and 47 deletions

View File

@ -41,17 +41,13 @@ static void dump_run(void)
die("non-threaded code path used");
}
dir = hashmap_iter_first(&the_index.dir_hash, &iter_dir);
while (dir) {
hashmap_for_each_entry(&the_index.dir_hash, &iter_dir, dir,
struct dir_entry, ent /* member name */)
printf("dir %08x %7d %s\n", dir->ent.hash, dir->nr, dir->name);
dir = hashmap_iter_next(&iter_dir);
}
ce = hashmap_iter_first(&the_index.name_hash, &iter_cache);
while (ce) {
hashmap_for_each_entry(&the_index.name_hash, &iter_cache, ce,
struct cache_entry, ent /* member name */)
printf("name %08x %s\n", ce->ent.hash, ce->name);
ce = hashmap_iter_next(&iter_cache);
}
discard_cache();
}