Skip to content

Commit 26b455f

Browse files
Eric Wonggitster
authored andcommitted
hashmap_put takes "struct hashmap_entry *"
This is less error-prone than "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 28ee794 commit 26b455f

File tree

11 files changed

+15
-12
lines changed

11 files changed

+15
-12
lines changed

builtin/fast-export.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static const void *anonymize_mem(struct hashmap *map,
160160
ret->orig_len = *len;
161161
ret->anon = generate(orig, len);
162162
ret->anon_len = *len;
163-
hashmap_put(map, ret);
163+
hashmap_put(map, &ret->hash);
164164
}
165165

166166
*len = ret->anon_len;

hashmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void *hashmap_remove(struct hashmap *map, const struct hashmap_entry *key,
241241
return old;
242242
}
243243

244-
void *hashmap_put(struct hashmap *map, void *entry)
244+
void *hashmap_put(struct hashmap *map, struct hashmap_entry *entry)
245245
{
246246
struct hashmap_entry *old = hashmap_remove(map, entry, NULL);
247247
hashmap_add(map, entry);

hashmap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ void hashmap_add(struct hashmap *map, struct hashmap_entry *entry);
340340
* `entry` is the entry to add or replace.
341341
* Returns the replaced entry, or NULL if not found (i.e. the entry was added).
342342
*/
343-
void *hashmap_put(struct hashmap *map, void *entry);
343+
void *hashmap_put(struct hashmap *map, struct hashmap_entry *entry);
344344

345345
/*
346346
* Removes a hashmap entry matching the specified key. If the hashmap contains

merge-recursive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,7 +2229,7 @@ static struct hashmap *get_directory_renames(struct diff_queue_struct *pairs)
22292229
if (!entry) {
22302230
entry = xmalloc(sizeof(*entry));
22312231
dir_rename_entry_init(entry, old_dir);
2232-
hashmap_put(dir_renames, entry);
2232+
hashmap_put(dir_renames, &entry->ent);
22332233
} else {
22342234
free(old_dir);
22352235
}
@@ -2360,7 +2360,7 @@ static void compute_collisions(struct hashmap *collisions,
23602360
sizeof(struct collision_entry));
23612361
hashmap_entry_init(&collision_ent->ent,
23622362
strhash(new_path));
2363-
hashmap_put(collisions, collision_ent);
2363+
hashmap_put(collisions, &collision_ent->ent);
23642364
collision_ent->target_file = new_path;
23652365
} else {
23662366
free(new_path);

oidmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ void *oidmap_put(struct oidmap *map, void *entry)
5151
oidmap_init(map, 0);
5252

5353
hashmap_entry_init(&to_put->internal_entry, oidhash(&to_put->oid));
54-
return hashmap_put(&map->map, to_put);
54+
return hashmap_put(&map->map, &to_put->internal_entry);
5555
}

refs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1863,10 +1863,13 @@ static void register_ref_store_map(struct hashmap *map,
18631863
struct ref_store *refs,
18641864
const char *name)
18651865
{
1866+
struct ref_store_hash_entry *entry;
1867+
18661868
if (!map->tablesize)
18671869
hashmap_init(map, ref_store_hash_cmp, NULL, 0);
18681870

1869-
if (hashmap_put(map, alloc_ref_store_hash_entry(name, refs)))
1871+
entry = alloc_ref_store_hash_entry(name, refs);
1872+
if (hashmap_put(map, &entry->ent))
18701873
BUG("%s ref_store '%s' initialized twice", type, name);
18711874
}
18721875

remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static struct remote *make_remote(const char *name, int len)
159159
remotes[remotes_nr++] = ret;
160160

161161
hashmap_entry_init(&ret->ent, lookup_entry.hash);
162-
replaced = hashmap_put(&remotes_hash, ret);
162+
replaced = hashmap_put(&remotes_hash, &ret->ent);
163163
assert(replaced == NULL); /* no previous entry overwritten */
164164
return ret;
165165
}

revision.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static void paths_and_oids_insert(struct hashmap *map,
153153
hashmap_entry_init(&entry->ent, hash);
154154
entry->path = xstrdup(key.path);
155155
oidset_init(&entry->trees, 16);
156-
hashmap_put(map, entry);
156+
hashmap_put(map, &entry->ent);
157157
}
158158

159159
oidset_insert(&entry->trees, oid);

sequencer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5254,7 +5254,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
52545254
entry->i = i;
52555255
hashmap_entry_init(&entry->entry,
52565256
strhash(entry->subject));
5257-
hashmap_put(&subject2item, entry);
5257+
hashmap_put(&subject2item, &entry->entry);
52585258
}
52595259
}
52605260

submodule-config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static void cache_put_path(struct submodule_cache *cache,
125125
struct submodule_entry *e = xmalloc(sizeof(*e));
126126
hashmap_entry_init(&e->ent, hash);
127127
e->config = submodule;
128-
hashmap_put(&cache->for_path, e);
128+
hashmap_put(&cache->for_path, &e->ent);
129129
}
130130

131131
static void cache_remove_path(struct submodule_cache *cache,

0 commit comments

Comments
 (0)