Skip to content

Commit f6eb6bd

Browse files
Eric Wonggitster
authored andcommitted
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 <[email protected]> Reviewed-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d22245a commit f6eb6bd

File tree

6 files changed

+11
-8
lines changed

6 files changed

+11
-8
lines changed

diff.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ static void pmb_advance_or_null_multi_match(struct diff_options *o,
10361036
int i;
10371037
char *got_match = xcalloc(1, pmb_nr);
10381038

1039-
for (; match; match = hashmap_get_next(hm, match)) {
1039+
for (; match; match = hashmap_get_next(hm, &match->ent)) {
10401040
for (i = 0; i < pmb_nr; i++) {
10411041
struct moved_entry *prev = pmb[i].match;
10421042
struct moved_entry *cur = (prev && prev->next_line) ?
@@ -1189,7 +1189,8 @@ static void mark_color_as_moved(struct diff_options *o,
11891189
* The current line is the start of a new block.
11901190
* Setup the set of potential blocks.
11911191
*/
1192-
for (; match; match = hashmap_get_next(hm, match)) {
1192+
for (; match; match = hashmap_get_next(hm,
1193+
&match->ent)) {
11931194
ALLOC_GROW(pmb, pmb_nr + 1, pmb_alloc);
11941195
if (o->color_moved_ws_handling &
11951196
COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) {

diffcore-rename.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static int find_identical_files(struct hashmap *srcs,
285285
p = hashmap_get_from_hash(srcs,
286286
hash_filespec(options->repo, target),
287287
NULL);
288-
for (; p; p = hashmap_get_next(srcs, p)) {
288+
for (; p; p = hashmap_get_next(srcs, &p->entry)) {
289289
int score;
290290
struct diff_filespec *source = p->filespec;
291291

hashmap.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,10 @@ void *hashmap_get(const struct hashmap *map, const void *key, const void *keydat
191191
return *find_entry_ptr(map, key, keydata);
192192
}
193193

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)
195196
{
196-
struct hashmap_entry *e = ((struct hashmap_entry *) entry)->next;
197+
struct hashmap_entry *e = entry->next;
197198
for (; e; e = e->next)
198199
if (entry_equals(map, entry, e, NULL))
199200
return e;

hashmap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ static inline void *hashmap_get_from_hash(const struct hashmap *map,
318318
* `entry` is the hashmap_entry to start the search from, obtained via a previous
319319
* call to `hashmap_get` or `hashmap_get_next`.
320320
*/
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);
322323

323324
/*
324325
* Adds a hashmap entry. This allows to add duplicate entries (i.e.

name-hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ struct cache_entry *index_file_exists(struct index_state *istate, const char *na
710710
while (ce) {
711711
if (same_name(ce, name, namelen, icase))
712712
return ce;
713-
ce = hashmap_get_next(&istate->name_hash, ce);
713+
ce = hashmap_get_next(&istate->name_hash, &ce->ent);
714714
}
715715
return NULL;
716716
}

t/helper/test-hashmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ int cmd__hashmap(int argc, const char **argv)
203203
puts("NULL");
204204
while (entry) {
205205
puts(get_value(entry));
206-
entry = hashmap_get_next(&map, entry);
206+
entry = hashmap_get_next(&map, &entry->ent);
207207
}
208208

209209
} else if (!strcmp("remove", cmd) && p1) {

0 commit comments

Comments
 (0)