hashmap_get_next takes "const struct hashmap_entry *"
This is less error-prone than "const void *" as the compiler now detects invalid types being passed. Signed-off-by: Eric Wong <e@80x24.org> Reviewed-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Wong committed
Oct 6, 2019 at 23:30 UTC
f6eb6bdcf2719defc3d38e0e2712fa3e18d29e91
6 files changed
+11
-8
diff.c
+3
-2
@@ -1036,7 +1036,7 @@ static void pmb_advance_or_null_multi_match(struct diff_options *o,
1036
int i;
1037
char *got_match = xcalloc(1, pmb_nr);
1038
1039
- for (; match; match = hashmap_get_next(hm, match)) {
1039
+ for (; match; match = hashmap_get_next(hm, &match->ent)) {
1040
for (i = 0; i < pmb_nr; i++) {
1041
struct moved_entry *prev = pmb[i].match;
1042
struct moved_entry *cur = (prev && prev->next_line) ?
@@ -1189,7 +1189,8 @@ static void mark_color_as_moved(struct diff_options *o,
1189
* The current line is the start of a new block.
1190
* Setup the set of potential blocks.
1191
*/
1192
- for (; match; match = hashmap_get_next(hm, match)) {
1192
+ for (; match; match = hashmap_get_next(hm,
1193
+ &match->ent)) {
1194
ALLOC_GROW(pmb, pmb_nr + 1, pmb_alloc);
1195
if (o->color_moved_ws_handling &
1196
COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) {
diffcore-rename.c
+1
-1
@@ -285,7 +285,7 @@ static int find_identical_files(struct hashmap *srcs,
285
p = hashmap_get_from_hash(srcs,
286
hash_filespec(options->repo, target),
287
NULL);
288
- for (; p; p = hashmap_get_next(srcs, p)) {
288
+ for (; p; p = hashmap_get_next(srcs, &p->entry)) {
289
int score;
290
struct diff_filespec *source = p->filespec;
291
hashmap.c
+3
-2
@@ -191,9 +191,10 @@ void *hashmap_get(const struct hashmap *map, const void *key, const void *keydat
191
return *find_entry_ptr(map, key, keydata);
192
}
193
194
-void *hashmap_get_next(const struct hashmap *map, const void *entry)
194
+void *hashmap_get_next(const struct hashmap *map,
195
+ const struct hashmap_entry *entry)
196
{
196
- struct hashmap_entry *e = ((struct hashmap_entry *) entry)->next;
197
+ struct hashmap_entry *e = entry->next;
198
for (; e; e = e->next)
199
if (entry_equals(map, entry, e, NULL))
200
return e;
hashmap.h
+2
-1
@@ -318,7 +318,8 @@ static inline void *hashmap_get_from_hash(const struct hashmap *map,
318
* `entry` is the hashmap_entry to start the search from, obtained via a previous
319
* call to `hashmap_get` or `hashmap_get_next`.
320
*/
321
-void *hashmap_get_next(const struct hashmap *map, const void *entry);
321
+void *hashmap_get_next(const struct hashmap *map,
322
+ const struct hashmap_entry *entry);
323
324
/*
325
* Adds a hashmap entry. This allows to add duplicate entries (i.e.
name-hash.c
+1
-1
@@ -710,7 +710,7 @@ struct cache_entry *index_file_exists(struct index_state *istate, const char *na
710
while (ce) {
711
if (same_name(ce, name, namelen, icase))
712
return ce;
713
- ce = hashmap_get_next(&istate->name_hash, ce);
713
+ ce = hashmap_get_next(&istate->name_hash, &ce->ent);
714
}
715
return NULL;
716
}
t/helper/test-hashmap.c
+1
-1
@@ -203,7 +203,7 @@ int cmd__hashmap(int argc, const char **argv)
203
puts("NULL");
204
while (entry) {
205
puts(get_value(entry));
206
- entry = hashmap_get_next(&map, entry);
206
+ entry = hashmap_get_next(&map, &entry->ent);
207
}
208
209
} else if (!strcmp("remove", cmd) && p1) {