hashmap_get 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 <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
b6c5241606e67b57470e86ccf547d4ab90008a1d
14 files changed
+28
-23
attr.c
+1
-1
@@ -101,7 +101,7 @@ static void *attr_hashmap_get(struct attr_hashmap *map,
101
hashmap_entry_init(&k.ent, memhash(key, keylen));
102
k.key = key;
103
k.keylen = keylen;
104
- e = hashmap_get(&map->map, &k, NULL);
104
+ e = hashmap_get(&map->map, &k.ent, NULL);
105
106
return e ? e->value : NULL;
107
}
blame.c
+3
-3
@@ -419,7 +419,7 @@ static void get_fingerprint(struct fingerprint *result,
419
continue;
420
hashmap_entry_init(&entry->entry, hash);
421
422
- found_entry = hashmap_get(&result->map, entry, NULL);
422
+ found_entry = hashmap_get(&result->map, &entry->entry, NULL);
423
if (found_entry) {
424
found_entry->count += 1;
425
} else {
@@ -452,7 +452,7 @@ static int fingerprint_similarity(struct fingerprint *a, struct fingerprint *b)
452
hashmap_iter_init(&b->map, &iter);
453
454
while ((entry_b = hashmap_iter_next(&iter))) {
455
- if ((entry_a = hashmap_get(&a->map, entry_b, NULL))) {
455
+ if ((entry_a = hashmap_get(&a->map, &entry_b->entry, NULL))) {
456
intersection += entry_a->count < entry_b->count ?
457
entry_a->count : entry_b->count;
458
}
@@ -471,7 +471,7 @@ static void fingerprint_subtract(struct fingerprint *a, struct fingerprint *b)
471
hashmap_iter_init(&b->map, &iter);
472
473
while ((entry_b = hashmap_iter_next(&iter))) {
474
- if ((entry_a = hashmap_get(&a->map, entry_b, NULL))) {
474
+ if ((entry_a = hashmap_get(&a->map, &entry_b->entry, NULL))) {
475
if (entry_a->count <= entry_b->count)
476
hashmap_remove(&a->map, entry_b, NULL);
477
else
builtin/difftool.c
+3
-2
@@ -162,7 +162,7 @@ static void add_left_or_right(struct hashmap *map, const char *path,
162
163
FLEX_ALLOC_STR(e, path, path);
164
hashmap_entry_init(&e->entry, strhash(path));
165
- existing = hashmap_get(map, e, NULL);
165
+ existing = hashmap_get(map, &e->entry, NULL);
166
if (existing) {
167
free(e);
168
e = existing;
@@ -462,7 +462,8 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
462
/* Avoid duplicate working_tree entries */
463
FLEX_ALLOC_STR(entry, path, dst_path);
464
hashmap_entry_init(&entry->entry, strhash(dst_path));
465
- if (hashmap_get(&working_tree_dups, entry, NULL)) {
465
+ if (hashmap_get(&working_tree_dups, &entry->entry,
466
+ NULL)) {
467
free(entry);
468
continue;
469
}
builtin/fast-export.c
+1
-1
@@ -151,7 +151,7 @@ static const void *anonymize_mem(struct hashmap *map,
151
hashmap_entry_init(&key.hash, memhash(orig, *len));
152
key.orig = orig;
153
key.orig_len = *len;
154
- ret = hashmap_get(map, &key, NULL);
154
+ ret = hashmap_get(map, &key.hash, NULL);
155
156
if (!ret) {
157
ret = xmalloc(sizeof(*ret));
config.c
+1
-1
@@ -1863,7 +1863,7 @@ static struct config_set_element *configset_find_element(struct config_set *cs,
1863
1864
hashmap_entry_init(&k.ent, strhash(normalized_key));
1865
k.key = normalized_key;
1866
- found_entry = hashmap_get(&cs->config_hash, &k, NULL);
1866
+ found_entry = hashmap_get(&cs->config_hash, &k.ent, NULL);
1867
free(normalized_key);
1868
return found_entry;
1869
}
diff.c
+2
-2
@@ -1144,13 +1144,13 @@ static void mark_color_as_moved(struct diff_options *o,
1144
case DIFF_SYMBOL_PLUS:
1145
hm = del_lines;
1146
key = prepare_entry(o, n);
1147
- match = hashmap_get(hm, key, NULL);
1147
+ match = hashmap_get(hm, &key->ent, NULL);
1148
free(key);
1149
break;
1150
case DIFF_SYMBOL_MINUS:
1151
hm = add_lines;
1152
key = prepare_entry(o, n);
1153
- match = hashmap_get(hm, key, NULL);
1153
+ match = hashmap_get(hm, &key->ent, NULL);
1154
free(key);
1155
break;
1156
default:
hashmap.c
+3
-2
@@ -186,7 +186,8 @@ void hashmap_free(struct hashmap *map, int free_entries)
186
memset(map, 0, sizeof(*map));
187
}
188
189
-void *hashmap_get(const struct hashmap *map, const void *key, const void *keydata)
189
+void *hashmap_get(const struct hashmap *map, const struct hashmap_entry *key,
190
+ const void *keydata)
191
{
192
return *find_entry_ptr(map, key, keydata);
193
}
@@ -296,7 +297,7 @@ const void *memintern(const void *data, size_t len)
297
/* lookup interned string in pool */
298
hashmap_entry_init(&key.ent, memhash(data, len));
299
key.len = len;
299
- e = hashmap_get(&map, &key, data);
300
+ e = hashmap_get(&map, &key.ent, data);
301
if (!e) {
302
/* not found: create it */
303
FLEX_ALLOC_MEM(e, data, data, len);
hashmap.h
+5
-3
@@ -74,7 +74,8 @@
74
* e->key = key;
75
*
76
* flags |= COMPARE_VALUE;
77
- * printf("%sfound\n", hashmap_get(&map, e, NULL) ? "" : "not ");
77
+ * printf("%sfound\n",
78
+ * hashmap_get(&map, &e->ent, NULL) ? "" : "not ");
79
* free(e);
80
* }
81
*
@@ -84,7 +85,8 @@
85
* k.key = key;
86
*
87
* flags |= COMPARE_VALUE;
87
- * printf("%sfound\n", hashmap_get(&map, &k, value) ? "" : "not ");
88
+ * printf("%sfound\n",
89
+ * hashmap_get(&map, &k->ent, value) ? "" : "not ");
90
* }
91
*
92
* if (!strcmp("end", action)) {
@@ -286,7 +288,7 @@ static inline unsigned int hashmap_get_size(struct hashmap *map)
288
* If an entry with matching hash code is found, `key` and `keydata` are passed
289
* to `hashmap_cmp_fn` to decide whether the entry matches the key.
290
*/
289
-void *hashmap_get(const struct hashmap *map, const void *key,
291
+void *hashmap_get(const struct hashmap *map, const struct hashmap_entry *key,
292
const void *keydata);
293
294
/*
merge-recursive.c
+2
-2
@@ -63,7 +63,7 @@ static struct dir_rename_entry *dir_rename_find_entry(struct hashmap *hashmap,
63
return NULL;
64
hashmap_entry_init(&key.ent, strhash(dir));
65
key.dir = dir;
66
- return hashmap_get(hashmap, &key, NULL);
66
+ return hashmap_get(hashmap, &key.ent, NULL);
67
}
68
69
static int dir_rename_cmp(const void *unused_cmp_data,
@@ -99,7 +99,7 @@ static struct collision_entry *collision_find_entry(struct hashmap *hashmap,
99
100
hashmap_entry_init(&key.ent, strhash(target_file));
101
key.target_file = target_file;
102
- return hashmap_get(hashmap, &key, NULL);
102
+ return hashmap_get(hashmap, &key.ent, NULL);
103
}
104
105
static int collision_cmp(void *unused_cmp_data,
name-hash.c
+1
-1
@@ -35,7 +35,7 @@ static struct dir_entry *find_dir_entry__hash(struct index_state *istate,
35
struct dir_entry key;
36
hashmap_entry_init(&key.ent, hash);
37
key.namelen = namelen;
38
- return hashmap_get(&istate->dir_hash, &key, name);
38
+ return hashmap_get(&istate->dir_hash, &key.ent, name);
39
}
40
41
static struct dir_entry *find_dir_entry(struct index_state *istate,
patch-ids.c
+1
-1
@@ -99,7 +99,7 @@ struct patch_id *has_commit_patch_id(struct commit *commit,
99
if (init_patch_id_entry(&patch, commit, ids))
100
return NULL;
101
102
- return hashmap_get(&ids->patches, &patch, NULL);
102
+ return hashmap_get(&ids->patches, &patch.ent, NULL);
103
}
104
105
struct patch_id *add_commit_patch_id(struct commit *commit,
revision.c
+2
-1
@@ -147,7 +147,8 @@ static void paths_and_oids_insert(struct hashmap *map,
147
key.path = (char *)path;
148
oidset_init(&key.trees, 0);
149
150
- if (!(entry = (struct path_and_oids_entry *)hashmap_get(map, &key, NULL))) {
150
+ entry = hashmap_get(map, &key.ent, NULL);
151
+ if (!entry) {
152
entry = xcalloc(1, sizeof(struct path_and_oids_entry));
153
hashmap_entry_init(&entry->ent, hash);
154
entry->path = xstrdup(key.path);
sub-process.c
+1
-1
@@ -22,7 +22,7 @@ struct subprocess_entry *subprocess_find_entry(struct hashmap *hashmap, const ch
22
23
hashmap_entry_init(&key.ent, strhash(cmd));
24
key.cmd = cmd;
25
- return hashmap_get(hashmap, &key, NULL);
25
+ return hashmap_get(hashmap, &key.ent, NULL);
26
}
27
28
int subprocess_read_status(int fd, struct strbuf *status)
submodule-config.c
+2
-2
@@ -166,7 +166,7 @@ static const struct submodule *cache_lookup_path(struct submodule_cache *cache,
166
hashmap_entry_init(&key.ent, hash);
167
key.config = &key_config;
168
169
- entry = hashmap_get(&cache->for_path, &key, NULL);
169
+ entry = hashmap_get(&cache->for_path, &key.ent, NULL);
170
if (entry)
171
return entry->config;
172
return NULL;
@@ -186,7 +186,7 @@ static struct submodule *cache_lookup_name(struct submodule_cache *cache,
186
hashmap_entry_init(&key.ent, hash);
187
key.config = &key_config;
188
189
- entry = hashmap_get(&cache->for_name, &key, NULL);
189
+ entry = hashmap_get(&cache->for_name, &key.ent, NULL);
190
if (entry)
191
return entry->config;
192
return NULL;