mirror of
https://github.com/git/git.git
synced 2024-11-24 02:17:02 +08:00
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>
This commit is contained in:
parent
b94e5c1df6
commit
b6c5241606
2
attr.c
2
attr.c
@ -101,7 +101,7 @@ static void *attr_hashmap_get(struct attr_hashmap *map,
|
|||||||
hashmap_entry_init(&k.ent, memhash(key, keylen));
|
hashmap_entry_init(&k.ent, memhash(key, keylen));
|
||||||
k.key = key;
|
k.key = key;
|
||||||
k.keylen = keylen;
|
k.keylen = keylen;
|
||||||
e = hashmap_get(&map->map, &k, NULL);
|
e = hashmap_get(&map->map, &k.ent, NULL);
|
||||||
|
|
||||||
return e ? e->value : NULL;
|
return e ? e->value : NULL;
|
||||||
}
|
}
|
||||||
|
6
blame.c
6
blame.c
@ -419,7 +419,7 @@ static void get_fingerprint(struct fingerprint *result,
|
|||||||
continue;
|
continue;
|
||||||
hashmap_entry_init(&entry->entry, hash);
|
hashmap_entry_init(&entry->entry, hash);
|
||||||
|
|
||||||
found_entry = hashmap_get(&result->map, entry, NULL);
|
found_entry = hashmap_get(&result->map, &entry->entry, NULL);
|
||||||
if (found_entry) {
|
if (found_entry) {
|
||||||
found_entry->count += 1;
|
found_entry->count += 1;
|
||||||
} else {
|
} else {
|
||||||
@ -452,7 +452,7 @@ static int fingerprint_similarity(struct fingerprint *a, struct fingerprint *b)
|
|||||||
hashmap_iter_init(&b->map, &iter);
|
hashmap_iter_init(&b->map, &iter);
|
||||||
|
|
||||||
while ((entry_b = hashmap_iter_next(&iter))) {
|
while ((entry_b = hashmap_iter_next(&iter))) {
|
||||||
if ((entry_a = hashmap_get(&a->map, entry_b, NULL))) {
|
if ((entry_a = hashmap_get(&a->map, &entry_b->entry, NULL))) {
|
||||||
intersection += entry_a->count < entry_b->count ?
|
intersection += entry_a->count < entry_b->count ?
|
||||||
entry_a->count : entry_b->count;
|
entry_a->count : entry_b->count;
|
||||||
}
|
}
|
||||||
@ -471,7 +471,7 @@ static void fingerprint_subtract(struct fingerprint *a, struct fingerprint *b)
|
|||||||
hashmap_iter_init(&b->map, &iter);
|
hashmap_iter_init(&b->map, &iter);
|
||||||
|
|
||||||
while ((entry_b = hashmap_iter_next(&iter))) {
|
while ((entry_b = hashmap_iter_next(&iter))) {
|
||||||
if ((entry_a = hashmap_get(&a->map, entry_b, NULL))) {
|
if ((entry_a = hashmap_get(&a->map, &entry_b->entry, NULL))) {
|
||||||
if (entry_a->count <= entry_b->count)
|
if (entry_a->count <= entry_b->count)
|
||||||
hashmap_remove(&a->map, entry_b, NULL);
|
hashmap_remove(&a->map, entry_b, NULL);
|
||||||
else
|
else
|
||||||
|
@ -162,7 +162,7 @@ static void add_left_or_right(struct hashmap *map, const char *path,
|
|||||||
|
|
||||||
FLEX_ALLOC_STR(e, path, path);
|
FLEX_ALLOC_STR(e, path, path);
|
||||||
hashmap_entry_init(&e->entry, strhash(path));
|
hashmap_entry_init(&e->entry, strhash(path));
|
||||||
existing = hashmap_get(map, e, NULL);
|
existing = hashmap_get(map, &e->entry, NULL);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
free(e);
|
free(e);
|
||||||
e = existing;
|
e = existing;
|
||||||
@ -462,7 +462,8 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
|
|||||||
/* Avoid duplicate working_tree entries */
|
/* Avoid duplicate working_tree entries */
|
||||||
FLEX_ALLOC_STR(entry, path, dst_path);
|
FLEX_ALLOC_STR(entry, path, dst_path);
|
||||||
hashmap_entry_init(&entry->entry, strhash(dst_path));
|
hashmap_entry_init(&entry->entry, strhash(dst_path));
|
||||||
if (hashmap_get(&working_tree_dups, entry, NULL)) {
|
if (hashmap_get(&working_tree_dups, &entry->entry,
|
||||||
|
NULL)) {
|
||||||
free(entry);
|
free(entry);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ static const void *anonymize_mem(struct hashmap *map,
|
|||||||
hashmap_entry_init(&key.hash, memhash(orig, *len));
|
hashmap_entry_init(&key.hash, memhash(orig, *len));
|
||||||
key.orig = orig;
|
key.orig = orig;
|
||||||
key.orig_len = *len;
|
key.orig_len = *len;
|
||||||
ret = hashmap_get(map, &key, NULL);
|
ret = hashmap_get(map, &key.hash, NULL);
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
ret = xmalloc(sizeof(*ret));
|
ret = xmalloc(sizeof(*ret));
|
||||||
|
2
config.c
2
config.c
@ -1863,7 +1863,7 @@ static struct config_set_element *configset_find_element(struct config_set *cs,
|
|||||||
|
|
||||||
hashmap_entry_init(&k.ent, strhash(normalized_key));
|
hashmap_entry_init(&k.ent, strhash(normalized_key));
|
||||||
k.key = normalized_key;
|
k.key = normalized_key;
|
||||||
found_entry = hashmap_get(&cs->config_hash, &k, NULL);
|
found_entry = hashmap_get(&cs->config_hash, &k.ent, NULL);
|
||||||
free(normalized_key);
|
free(normalized_key);
|
||||||
return found_entry;
|
return found_entry;
|
||||||
}
|
}
|
||||||
|
4
diff.c
4
diff.c
@ -1144,13 +1144,13 @@ static void mark_color_as_moved(struct diff_options *o,
|
|||||||
case DIFF_SYMBOL_PLUS:
|
case DIFF_SYMBOL_PLUS:
|
||||||
hm = del_lines;
|
hm = del_lines;
|
||||||
key = prepare_entry(o, n);
|
key = prepare_entry(o, n);
|
||||||
match = hashmap_get(hm, key, NULL);
|
match = hashmap_get(hm, &key->ent, NULL);
|
||||||
free(key);
|
free(key);
|
||||||
break;
|
break;
|
||||||
case DIFF_SYMBOL_MINUS:
|
case DIFF_SYMBOL_MINUS:
|
||||||
hm = add_lines;
|
hm = add_lines;
|
||||||
key = prepare_entry(o, n);
|
key = prepare_entry(o, n);
|
||||||
match = hashmap_get(hm, key, NULL);
|
match = hashmap_get(hm, &key->ent, NULL);
|
||||||
free(key);
|
free(key);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -186,7 +186,8 @@ void hashmap_free(struct hashmap *map, int free_entries)
|
|||||||
memset(map, 0, sizeof(*map));
|
memset(map, 0, sizeof(*map));
|
||||||
}
|
}
|
||||||
|
|
||||||
void *hashmap_get(const struct hashmap *map, const void *key, const void *keydata)
|
void *hashmap_get(const struct hashmap *map, const struct hashmap_entry *key,
|
||||||
|
const void *keydata)
|
||||||
{
|
{
|
||||||
return *find_entry_ptr(map, key, keydata);
|
return *find_entry_ptr(map, key, keydata);
|
||||||
}
|
}
|
||||||
@ -296,7 +297,7 @@ const void *memintern(const void *data, size_t len)
|
|||||||
/* lookup interned string in pool */
|
/* lookup interned string in pool */
|
||||||
hashmap_entry_init(&key.ent, memhash(data, len));
|
hashmap_entry_init(&key.ent, memhash(data, len));
|
||||||
key.len = len;
|
key.len = len;
|
||||||
e = hashmap_get(&map, &key, data);
|
e = hashmap_get(&map, &key.ent, data);
|
||||||
if (!e) {
|
if (!e) {
|
||||||
/* not found: create it */
|
/* not found: create it */
|
||||||
FLEX_ALLOC_MEM(e, data, data, len);
|
FLEX_ALLOC_MEM(e, data, data, len);
|
||||||
|
@ -74,7 +74,8 @@
|
|||||||
* e->key = key;
|
* e->key = key;
|
||||||
*
|
*
|
||||||
* flags |= COMPARE_VALUE;
|
* flags |= COMPARE_VALUE;
|
||||||
* printf("%sfound\n", hashmap_get(&map, e, NULL) ? "" : "not ");
|
* printf("%sfound\n",
|
||||||
|
* hashmap_get(&map, &e->ent, NULL) ? "" : "not ");
|
||||||
* free(e);
|
* free(e);
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
@ -84,7 +85,8 @@
|
|||||||
* k.key = key;
|
* k.key = key;
|
||||||
*
|
*
|
||||||
* flags |= COMPARE_VALUE;
|
* flags |= COMPARE_VALUE;
|
||||||
* printf("%sfound\n", hashmap_get(&map, &k, value) ? "" : "not ");
|
* printf("%sfound\n",
|
||||||
|
* hashmap_get(&map, &k->ent, value) ? "" : "not ");
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* if (!strcmp("end", action)) {
|
* if (!strcmp("end", action)) {
|
||||||
@ -286,7 +288,7 @@ static inline unsigned int hashmap_get_size(struct hashmap *map)
|
|||||||
* If an entry with matching hash code is found, `key` and `keydata` are passed
|
* If an entry with matching hash code is found, `key` and `keydata` are passed
|
||||||
* to `hashmap_cmp_fn` to decide whether the entry matches the key.
|
* to `hashmap_cmp_fn` to decide whether the entry matches the key.
|
||||||
*/
|
*/
|
||||||
void *hashmap_get(const struct hashmap *map, const void *key,
|
void *hashmap_get(const struct hashmap *map, const struct hashmap_entry *key,
|
||||||
const void *keydata);
|
const void *keydata);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -63,7 +63,7 @@ static struct dir_rename_entry *dir_rename_find_entry(struct hashmap *hashmap,
|
|||||||
return NULL;
|
return NULL;
|
||||||
hashmap_entry_init(&key.ent, strhash(dir));
|
hashmap_entry_init(&key.ent, strhash(dir));
|
||||||
key.dir = dir;
|
key.dir = dir;
|
||||||
return hashmap_get(hashmap, &key, NULL);
|
return hashmap_get(hashmap, &key.ent, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dir_rename_cmp(const void *unused_cmp_data,
|
static int dir_rename_cmp(const void *unused_cmp_data,
|
||||||
@ -99,7 +99,7 @@ static struct collision_entry *collision_find_entry(struct hashmap *hashmap,
|
|||||||
|
|
||||||
hashmap_entry_init(&key.ent, strhash(target_file));
|
hashmap_entry_init(&key.ent, strhash(target_file));
|
||||||
key.target_file = target_file;
|
key.target_file = target_file;
|
||||||
return hashmap_get(hashmap, &key, NULL);
|
return hashmap_get(hashmap, &key.ent, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int collision_cmp(void *unused_cmp_data,
|
static int collision_cmp(void *unused_cmp_data,
|
||||||
|
@ -35,7 +35,7 @@ static struct dir_entry *find_dir_entry__hash(struct index_state *istate,
|
|||||||
struct dir_entry key;
|
struct dir_entry key;
|
||||||
hashmap_entry_init(&key.ent, hash);
|
hashmap_entry_init(&key.ent, hash);
|
||||||
key.namelen = namelen;
|
key.namelen = namelen;
|
||||||
return hashmap_get(&istate->dir_hash, &key, name);
|
return hashmap_get(&istate->dir_hash, &key.ent, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct dir_entry *find_dir_entry(struct index_state *istate,
|
static struct dir_entry *find_dir_entry(struct index_state *istate,
|
||||||
|
@ -99,7 +99,7 @@ struct patch_id *has_commit_patch_id(struct commit *commit,
|
|||||||
if (init_patch_id_entry(&patch, commit, ids))
|
if (init_patch_id_entry(&patch, commit, ids))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return hashmap_get(&ids->patches, &patch, NULL);
|
return hashmap_get(&ids->patches, &patch.ent, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct patch_id *add_commit_patch_id(struct commit *commit,
|
struct patch_id *add_commit_patch_id(struct commit *commit,
|
||||||
|
@ -147,7 +147,8 @@ static void paths_and_oids_insert(struct hashmap *map,
|
|||||||
key.path = (char *)path;
|
key.path = (char *)path;
|
||||||
oidset_init(&key.trees, 0);
|
oidset_init(&key.trees, 0);
|
||||||
|
|
||||||
if (!(entry = (struct path_and_oids_entry *)hashmap_get(map, &key, NULL))) {
|
entry = hashmap_get(map, &key.ent, NULL);
|
||||||
|
if (!entry) {
|
||||||
entry = xcalloc(1, sizeof(struct path_and_oids_entry));
|
entry = xcalloc(1, sizeof(struct path_and_oids_entry));
|
||||||
hashmap_entry_init(&entry->ent, hash);
|
hashmap_entry_init(&entry->ent, hash);
|
||||||
entry->path = xstrdup(key.path);
|
entry->path = xstrdup(key.path);
|
||||||
|
@ -22,7 +22,7 @@ struct subprocess_entry *subprocess_find_entry(struct hashmap *hashmap, const ch
|
|||||||
|
|
||||||
hashmap_entry_init(&key.ent, strhash(cmd));
|
hashmap_entry_init(&key.ent, strhash(cmd));
|
||||||
key.cmd = cmd;
|
key.cmd = cmd;
|
||||||
return hashmap_get(hashmap, &key, NULL);
|
return hashmap_get(hashmap, &key.ent, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int subprocess_read_status(int fd, struct strbuf *status)
|
int subprocess_read_status(int fd, struct strbuf *status)
|
||||||
|
@ -166,7 +166,7 @@ static const struct submodule *cache_lookup_path(struct submodule_cache *cache,
|
|||||||
hashmap_entry_init(&key.ent, hash);
|
hashmap_entry_init(&key.ent, hash);
|
||||||
key.config = &key_config;
|
key.config = &key_config;
|
||||||
|
|
||||||
entry = hashmap_get(&cache->for_path, &key, NULL);
|
entry = hashmap_get(&cache->for_path, &key.ent, NULL);
|
||||||
if (entry)
|
if (entry)
|
||||||
return entry->config;
|
return entry->config;
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -186,7 +186,7 @@ static struct submodule *cache_lookup_name(struct submodule_cache *cache,
|
|||||||
hashmap_entry_init(&key.ent, hash);
|
hashmap_entry_init(&key.ent, hash);
|
||||||
key.config = &key_config;
|
key.config = &key_config;
|
||||||
|
|
||||||
entry = hashmap_get(&cache->for_name, &key, NULL);
|
entry = hashmap_get(&cache->for_name, &key.ent, NULL);
|
||||||
if (entry)
|
if (entry)
|
||||||
return entry->config;
|
return entry->config;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user