Skip to content

Commit

Permalink
hashmap_get_next takes "const struct hashmap_entry *"
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Eric Wong authored and gitster committed Aug 26, 2019
1 parent 7a55822 commit f3b5b29
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ static void pmb_advance_or_null_multi_match(struct diff_options *o,
int i;
char *got_match = xcalloc(1, pmb_nr);

for (; match; match = hashmap_get_next(hm, match)) {
for (; match; match = hashmap_get_next(hm, &match->ent)) {
for (i = 0; i < pmb_nr; i++) {
struct moved_entry *prev = pmb[i].match;
struct moved_entry *cur = (prev && prev->next_line) ?
Expand Down Expand Up @@ -1189,7 +1189,8 @@ static void mark_color_as_moved(struct diff_options *o,
* The current line is the start of a new block.
* Setup the set of potential blocks.
*/
for (; match; match = hashmap_get_next(hm, match)) {
for (; match; match = hashmap_get_next(hm,
&match->ent)) {
ALLOC_GROW(pmb, pmb_nr + 1, pmb_alloc);
if (o->color_moved_ws_handling &
COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) {
Expand Down
2 changes: 1 addition & 1 deletion diffcore-rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ static int find_identical_files(struct hashmap *srcs,
p = hashmap_get_from_hash(srcs,
hash_filespec(options->repo, target),
NULL);
for (; p; p = hashmap_get_next(srcs, p)) {
for (; p; p = hashmap_get_next(srcs, &p->entry)) {
int score;
struct diff_filespec *source = p->filespec;

Expand Down
5 changes: 3 additions & 2 deletions hashmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,10 @@ void *hashmap_get(const struct hashmap *map, const void *key, const void *keydat
return *find_entry_ptr(map, key, keydata);
}

void *hashmap_get_next(const struct hashmap *map, const void *entry)
void *hashmap_get_next(const struct hashmap *map,
const struct hashmap_entry *entry)
{
struct hashmap_entry *e = ((struct hashmap_entry *) entry)->next;
struct hashmap_entry *e = entry->next;
for (; e; e = e->next)
if (entry_equals(map, entry, e, NULL))
return e;
Expand Down
3 changes: 2 additions & 1 deletion hashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ static inline void *hashmap_get_from_hash(const struct hashmap *map,
* `entry` is the hashmap_entry to start the search from, obtained via a previous
* call to `hashmap_get` or `hashmap_get_next`.
*/
void *hashmap_get_next(const struct hashmap *map, const void *entry);
void *hashmap_get_next(const struct hashmap *map,
const struct hashmap_entry *entry);

/*
* Adds a hashmap entry. This allows to add duplicate entries (i.e.
Expand Down
2 changes: 1 addition & 1 deletion name-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ struct cache_entry *index_file_exists(struct index_state *istate, const char *na
while (ce) {
if (same_name(ce, name, namelen, icase))
return ce;
ce = hashmap_get_next(&istate->name_hash, ce);
ce = hashmap_get_next(&istate->name_hash, &ce->ent);
}
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion t/helper/test-hashmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ int cmd__hashmap(int argc, const char **argv)
puts("NULL");
while (entry) {
puts(get_value(entry));
entry = hashmap_get_next(&map, entry);
entry = hashmap_get_next(&map, &entry->ent);
}

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

0 comments on commit f3b5b29

Please sign in to comment.