Skip to content

Commit b6c5241

Browse files
Eric Wonggitster
authored andcommitted
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 <[email protected]> Reviewed-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b94e5c1 commit b6c5241

File tree

14 files changed

+28
-23
lines changed

14 files changed

+28
-23
lines changed

attr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static void *attr_hashmap_get(struct attr_hashmap *map,
101101
hashmap_entry_init(&k.ent, memhash(key, keylen));
102102
k.key = key;
103103
k.keylen = keylen;
104-
e = hashmap_get(&map->map, &k, NULL);
104+
e = hashmap_get(&map->map, &k.ent, NULL);
105105

106106
return e ? e->value : NULL;
107107
}

blame.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ static void get_fingerprint(struct fingerprint *result,
419419
continue;
420420
hashmap_entry_init(&entry->entry, hash);
421421

422-
found_entry = hashmap_get(&result->map, entry, NULL);
422+
found_entry = hashmap_get(&result->map, &entry->entry, NULL);
423423
if (found_entry) {
424424
found_entry->count += 1;
425425
} else {
@@ -452,7 +452,7 @@ static int fingerprint_similarity(struct fingerprint *a, struct fingerprint *b)
452452
hashmap_iter_init(&b->map, &iter);
453453

454454
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))) {
456456
intersection += entry_a->count < entry_b->count ?
457457
entry_a->count : entry_b->count;
458458
}
@@ -471,7 +471,7 @@ static void fingerprint_subtract(struct fingerprint *a, struct fingerprint *b)
471471
hashmap_iter_init(&b->map, &iter);
472472

473473
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))) {
475475
if (entry_a->count <= entry_b->count)
476476
hashmap_remove(&a->map, entry_b, NULL);
477477
else

builtin/difftool.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static void add_left_or_right(struct hashmap *map, const char *path,
162162

163163
FLEX_ALLOC_STR(e, path, path);
164164
hashmap_entry_init(&e->entry, strhash(path));
165-
existing = hashmap_get(map, e, NULL);
165+
existing = hashmap_get(map, &e->entry, NULL);
166166
if (existing) {
167167
free(e);
168168
e = existing;
@@ -462,7 +462,8 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
462462
/* Avoid duplicate working_tree entries */
463463
FLEX_ALLOC_STR(entry, path, dst_path);
464464
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)) {
466467
free(entry);
467468
continue;
468469
}

builtin/fast-export.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static const void *anonymize_mem(struct hashmap *map,
151151
hashmap_entry_init(&key.hash, memhash(orig, *len));
152152
key.orig = orig;
153153
key.orig_len = *len;
154-
ret = hashmap_get(map, &key, NULL);
154+
ret = hashmap_get(map, &key.hash, NULL);
155155

156156
if (!ret) {
157157
ret = xmalloc(sizeof(*ret));

config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,7 @@ static struct config_set_element *configset_find_element(struct config_set *cs,
18631863

18641864
hashmap_entry_init(&k.ent, strhash(normalized_key));
18651865
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);
18671867
free(normalized_key);
18681868
return found_entry;
18691869
}

diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,13 +1144,13 @@ static void mark_color_as_moved(struct diff_options *o,
11441144
case DIFF_SYMBOL_PLUS:
11451145
hm = del_lines;
11461146
key = prepare_entry(o, n);
1147-
match = hashmap_get(hm, key, NULL);
1147+
match = hashmap_get(hm, &key->ent, NULL);
11481148
free(key);
11491149
break;
11501150
case DIFF_SYMBOL_MINUS:
11511151
hm = add_lines;
11521152
key = prepare_entry(o, n);
1153-
match = hashmap_get(hm, key, NULL);
1153+
match = hashmap_get(hm, &key->ent, NULL);
11541154
free(key);
11551155
break;
11561156
default:

hashmap.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ void hashmap_free(struct hashmap *map, int free_entries)
186186
memset(map, 0, sizeof(*map));
187187
}
188188

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)
190191
{
191192
return *find_entry_ptr(map, key, keydata);
192193
}
@@ -296,7 +297,7 @@ const void *memintern(const void *data, size_t len)
296297
/* lookup interned string in pool */
297298
hashmap_entry_init(&key.ent, memhash(data, len));
298299
key.len = len;
299-
e = hashmap_get(&map, &key, data);
300+
e = hashmap_get(&map, &key.ent, data);
300301
if (!e) {
301302
/* not found: create it */
302303
FLEX_ALLOC_MEM(e, data, data, len);

hashmap.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
* e->key = key;
7575
*
7676
* 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 ");
7879
* free(e);
7980
* }
8081
*
@@ -84,7 +85,8 @@
8485
* k.key = key;
8586
*
8687
* 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 ");
8890
* }
8991
*
9092
* if (!strcmp("end", action)) {
@@ -286,7 +288,7 @@ static inline unsigned int hashmap_get_size(struct hashmap *map)
286288
* If an entry with matching hash code is found, `key` and `keydata` are passed
287289
* to `hashmap_cmp_fn` to decide whether the entry matches the key.
288290
*/
289-
void *hashmap_get(const struct hashmap *map, const void *key,
291+
void *hashmap_get(const struct hashmap *map, const struct hashmap_entry *key,
290292
const void *keydata);
291293

292294
/*

merge-recursive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static struct dir_rename_entry *dir_rename_find_entry(struct hashmap *hashmap,
6363
return NULL;
6464
hashmap_entry_init(&key.ent, strhash(dir));
6565
key.dir = dir;
66-
return hashmap_get(hashmap, &key, NULL);
66+
return hashmap_get(hashmap, &key.ent, NULL);
6767
}
6868

6969
static int dir_rename_cmp(const void *unused_cmp_data,
@@ -99,7 +99,7 @@ static struct collision_entry *collision_find_entry(struct hashmap *hashmap,
9999

100100
hashmap_entry_init(&key.ent, strhash(target_file));
101101
key.target_file = target_file;
102-
return hashmap_get(hashmap, &key, NULL);
102+
return hashmap_get(hashmap, &key.ent, NULL);
103103
}
104104

105105
static int collision_cmp(void *unused_cmp_data,

name-hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static struct dir_entry *find_dir_entry__hash(struct index_state *istate,
3535
struct dir_entry key;
3636
hashmap_entry_init(&key.ent, hash);
3737
key.namelen = namelen;
38-
return hashmap_get(&istate->dir_hash, &key, name);
38+
return hashmap_get(&istate->dir_hash, &key.ent, name);
3939
}
4040

4141
static struct dir_entry *find_dir_entry(struct index_state *istate,

0 commit comments

Comments
 (0)