Skip to content

Commit 28ee794

Browse files
Eric Wonggitster
authored andcommitted
hashmap_remove 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 b6c5241 commit 28ee794

File tree

9 files changed

+11
-10
lines changed

9 files changed

+11
-10
lines changed

blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ static void fingerprint_subtract(struct fingerprint *a, struct fingerprint *b)
473473
while ((entry_b = hashmap_iter_next(&iter))) {
474474
if ((entry_a = hashmap_get(&a->map, &entry_b->entry, NULL))) {
475475
if (entry_a->count <= entry_b->count)
476-
hashmap_remove(&a->map, entry_b, NULL);
476+
hashmap_remove(&a->map, &entry_b->entry, NULL);
477477
else
478478
entry_a->count -= entry_b->count;
479479
}

hashmap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ void hashmap_add(struct hashmap *map, struct hashmap_entry *entry)
218218
}
219219
}
220220

221-
void *hashmap_remove(struct hashmap *map, const void *key, const void *keydata)
221+
void *hashmap_remove(struct hashmap *map, const struct hashmap_entry *key,
222+
const void *keydata)
222223
{
223224
struct hashmap_entry *old;
224225
struct hashmap_entry **e = find_entry_ptr(map, key, keydata);

hashmap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ void *hashmap_put(struct hashmap *map, void *entry);
349349
*
350350
* Argument explanation is the same as in `hashmap_get`.
351351
*/
352-
void *hashmap_remove(struct hashmap *map, const void *key,
352+
void *hashmap_remove(struct hashmap *map, const struct hashmap_entry *key,
353353
const void *keydata);
354354

355355
/*

merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2001,7 +2001,7 @@ static void remove_hashmap_entries(struct hashmap *dir_renames,
20012001

20022002
for (i = 0; i < items_to_remove->nr; i++) {
20032003
entry = items_to_remove->items[i].util;
2004-
hashmap_remove(dir_renames, entry, NULL);
2004+
hashmap_remove(dir_renames, &entry->ent, NULL);
20052005
}
20062006
string_list_clear(items_to_remove, 0);
20072007
}

name-hash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void remove_dir_entry(struct index_state *istate, struct cache_entry *ce)
9595
struct dir_entry *dir = hash_dir_entry(istate, ce, ce_namelen(ce));
9696
while (dir && !(--dir->nr)) {
9797
struct dir_entry *parent = dir->parent;
98-
hashmap_remove(&istate->dir_hash, dir, NULL);
98+
hashmap_remove(&istate->dir_hash, &dir->ent, NULL);
9999
free(dir);
100100
dir = parent;
101101
}
@@ -625,7 +625,7 @@ void remove_name_hash(struct index_state *istate, struct cache_entry *ce)
625625
if (!istate->name_hash_initialized || !(ce->ce_flags & CE_HASHED))
626626
return;
627627
ce->ce_flags &= ~CE_HASHED;
628-
hashmap_remove(&istate->name_hash, ce, ce);
628+
hashmap_remove(&istate->name_hash, &ce->ent, ce);
629629

630630
if (ignore_case)
631631
remove_dir_entry(istate, ce);

packfile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ static int in_delta_base_cache(struct packed_git *p, off_t base_offset)
14231423
*/
14241424
static void detach_delta_base_cache_entry(struct delta_base_cache_entry *ent)
14251425
{
1426-
hashmap_remove(&delta_base_cache, ent, &ent->key);
1426+
hashmap_remove(&delta_base_cache, &ent->ent, &ent->key);
14271427
list_del(&ent->lru);
14281428
delta_base_cached -= ent->size;
14291429
free(ent);

range-diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ static void find_exact_matches(struct string_list *a, struct string_list *b)
229229
util->patch = b->items[i].string;
230230
util->diff = util->patch + util->diff_offset;
231231
hashmap_entry_init(&util->e, strhash(util->diff));
232-
other = hashmap_remove(&map, util, NULL);
232+
other = hashmap_remove(&map, &util->e, NULL);
233233
if (other) {
234234
if (other->matching >= 0)
235235
BUG("already assigned!");

sub-process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void subprocess_stop(struct hashmap *hashmap, struct subprocess_entry *entry)
5858
kill(entry->process.pid, SIGTERM);
5959
finish_command(&entry->process);
6060

61-
hashmap_remove(hashmap, entry, NULL);
61+
hashmap_remove(hashmap, &entry->ent, NULL);
6262
}
6363

6464
static void subprocess_exit_handler(struct child_process *process)

submodule-config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static void cache_remove_path(struct submodule_cache *cache,
137137
struct submodule_entry *removed;
138138
hashmap_entry_init(&e.ent, hash);
139139
e.config = submodule;
140-
removed = hashmap_remove(&cache->for_path, &e, NULL);
140+
removed = hashmap_remove(&cache->for_path, &e.ent, NULL);
141141
free(removed);
142142
}
143143

0 commit comments

Comments
 (0)