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 <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
26b455f21ed7e0c7b0e4e4e69b5ae48545597020
11 files changed
+15
-12
builtin/fast-export.c
+1
-1
@@ -160,7 +160,7 @@ static const void *anonymize_mem(struct hashmap *map,
160
ret->orig_len = *len;
161
ret->anon = generate(orig, len);
162
ret->anon_len = *len;
163
- hashmap_put(map, ret);
163
+ hashmap_put(map, &ret->hash);
164
}
165
166
*len = ret->anon_len;
hashmap.c
+1
-1
@@ -241,7 +241,7 @@ void *hashmap_remove(struct hashmap *map, const struct hashmap_entry *key,
241
return old;
242
}
243
244
-void *hashmap_put(struct hashmap *map, void *entry)
244
+void *hashmap_put(struct hashmap *map, struct hashmap_entry *entry)
245
{
246
struct hashmap_entry *old = hashmap_remove(map, entry, NULL);
247
hashmap_add(map, entry);
hashmap.h
+1
-1
@@ -340,7 +340,7 @@ void hashmap_add(struct hashmap *map, struct hashmap_entry *entry);
340
* `entry` is the entry to add or replace.
341
* Returns the replaced entry, or NULL if not found (i.e. the entry was added).
342
*/
343
-void *hashmap_put(struct hashmap *map, void *entry);
343
+void *hashmap_put(struct hashmap *map, struct hashmap_entry *entry);
344
345
/*
346
* Removes a hashmap entry matching the specified key. If the hashmap contains
merge-recursive.c
+2
-2
@@ -2229,7 +2229,7 @@ static struct hashmap *get_directory_renames(struct diff_queue_struct *pairs)
2229
if (!entry) {
2230
entry = xmalloc(sizeof(*entry));
2231
dir_rename_entry_init(entry, old_dir);
2232
- hashmap_put(dir_renames, entry);
2232
+ hashmap_put(dir_renames, &entry->ent);
2233
} else {
2234
free(old_dir);
2235
}
@@ -2360,7 +2360,7 @@ static void compute_collisions(struct hashmap *collisions,
2360
sizeof(struct collision_entry));
2361
hashmap_entry_init(&collision_ent->ent,
2362
strhash(new_path));
2363
- hashmap_put(collisions, collision_ent);
2363
+ hashmap_put(collisions, &collision_ent->ent);
2364
collision_ent->target_file = new_path;
2365
} else {
2366
free(new_path);
oidmap.c
+1
-1
@@ -51,5 +51,5 @@ void *oidmap_put(struct oidmap *map, void *entry)
51
oidmap_init(map, 0);
52
53
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);
55
}
refs.c
+4
-1
@@ -1863,10 +1863,13 @@ static void register_ref_store_map(struct hashmap *map,
1863
struct ref_store *refs,
1864
const char *name)
1865
{
1866
+ struct ref_store_hash_entry *entry;
1867
+
1868
if (!map->tablesize)
1869
hashmap_init(map, ref_store_hash_cmp, NULL, 0);
1870
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))
1873
BUG("%s ref_store '%s' initialized twice", type, name);
1874
}
1875
remote.c
+1
-1
@@ -159,7 +159,7 @@ static struct remote *make_remote(const char *name, int len)
159
remotes[remotes_nr++] = ret;
160
161
hashmap_entry_init(&ret->ent, lookup_entry.hash);
162
- replaced = hashmap_put(&remotes_hash, ret);
162
+ replaced = hashmap_put(&remotes_hash, &ret->ent);
163
assert(replaced == NULL); /* no previous entry overwritten */
164
return ret;
165
}
revision.c
+1
-1
@@ -153,7 +153,7 @@ static void paths_and_oids_insert(struct hashmap *map,
153
hashmap_entry_init(&entry->ent, hash);
154
entry->path = xstrdup(key.path);
155
oidset_init(&entry->trees, 16);
156
- hashmap_put(map, entry);
156
+ hashmap_put(map, &entry->ent);
157
}
158
159
oidset_insert(&entry->trees, oid);
sequencer.c
+1
-1
@@ -5254,7 +5254,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
5254
entry->i = i;
5255
hashmap_entry_init(&entry->entry,
5256
strhash(entry->subject));
5257
- hashmap_put(&subject2item, entry);
5257
+ hashmap_put(&subject2item, &entry->entry);
5258
}
5259
}
5260
submodule-config.c
+1
-1
@@ -125,7 +125,7 @@ static void cache_put_path(struct submodule_cache *cache,
125
struct submodule_entry *e = xmalloc(sizeof(*e));
126
hashmap_entry_init(&e->ent, hash);
127
e->config = submodule;
128
- hashmap_put(&cache->for_path, e);
128
+ hashmap_put(&cache->for_path, &e->ent);
129
}
130
131
static void cache_remove_path(struct submodule_cache *cache,
t/helper/test-hashmap.c
+1
-1
@@ -187,7 +187,7 @@ int cmd__hashmap(int argc, const char **argv)
187
entry = alloc_test_entry(hash, p1, p2);
188
189
/* add / replace entry */
190
- entry = hashmap_put(&map, entry);
190
+ entry = hashmap_put(&map, &entry->ent);
191
192
/* print and free replaced entry, if any */
193
puts(entry ? get_value(entry) : "NULL");