hashmap_add 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>
This commit is contained in:
parent
f6eb6bdcf2
commit
b94e5c1df6
2
attr.c
2
attr.c
@ -122,7 +122,7 @@ static void attr_hashmap_add(struct attr_hashmap *map,
|
|||||||
e->keylen = keylen;
|
e->keylen = keylen;
|
||||||
e->value = value;
|
e->value = value;
|
||||||
|
|
||||||
hashmap_add(&map->map, e);
|
hashmap_add(&map->map, &e->ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct all_attrs_item {
|
struct all_attrs_item {
|
||||||
|
2
blame.c
2
blame.c
@ -424,7 +424,7 @@ static void get_fingerprint(struct fingerprint *result,
|
|||||||
found_entry->count += 1;
|
found_entry->count += 1;
|
||||||
} else {
|
} else {
|
||||||
entry->count = 1;
|
entry->count = 1;
|
||||||
hashmap_add(&result->map, entry);
|
hashmap_add(&result->map, &entry->entry);
|
||||||
++entry;
|
++entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ static void add_to_known_names(const char *path,
|
|||||||
e = xmalloc(sizeof(struct commit_name));
|
e = xmalloc(sizeof(struct commit_name));
|
||||||
oidcpy(&e->peeled, peeled);
|
oidcpy(&e->peeled, peeled);
|
||||||
hashmap_entry_init(&e->entry, oidhash(peeled));
|
hashmap_entry_init(&e->entry, oidhash(peeled));
|
||||||
hashmap_add(&names, e);
|
hashmap_add(&names, &e->entry);
|
||||||
e->path = NULL;
|
e->path = NULL;
|
||||||
}
|
}
|
||||||
e->tag = tag;
|
e->tag = tag;
|
||||||
|
@ -168,7 +168,7 @@ static void add_left_or_right(struct hashmap *map, const char *path,
|
|||||||
e = existing;
|
e = existing;
|
||||||
} else {
|
} else {
|
||||||
e->left[0] = e->right[0] = '\0';
|
e->left[0] = e->right[0] = '\0';
|
||||||
hashmap_add(map, e);
|
hashmap_add(map, &e->entry);
|
||||||
}
|
}
|
||||||
strlcpy(is_right ? e->right : e->left, content, PATH_MAX);
|
strlcpy(is_right ? e->right : e->left, content, PATH_MAX);
|
||||||
}
|
}
|
||||||
@ -235,7 +235,7 @@ static void changed_files(struct hashmap *result, const char *index_path,
|
|||||||
struct path_entry *entry;
|
struct path_entry *entry;
|
||||||
FLEX_ALLOC_STR(entry, path, buf.buf);
|
FLEX_ALLOC_STR(entry, path, buf.buf);
|
||||||
hashmap_entry_init(&entry->entry, strhash(buf.buf));
|
hashmap_entry_init(&entry->entry, strhash(buf.buf));
|
||||||
hashmap_add(result, entry);
|
hashmap_add(result, &entry->entry);
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
if (finish_command(&diff_files))
|
if (finish_command(&diff_files))
|
||||||
@ -466,7 +466,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
|
|||||||
free(entry);
|
free(entry);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
hashmap_add(&working_tree_dups, entry);
|
hashmap_add(&working_tree_dups, &entry->entry);
|
||||||
|
|
||||||
if (!use_wt_file(workdir, dst_path, &roid)) {
|
if (!use_wt_file(workdir, dst_path, &roid)) {
|
||||||
if (checkout_path(rmode, &roid, dst_path,
|
if (checkout_path(rmode, &roid, dst_path,
|
||||||
|
@ -278,7 +278,7 @@ static struct refname_hash_entry *refname_hash_add(struct hashmap *map,
|
|||||||
FLEX_ALLOC_MEM(ent, refname, refname, len);
|
FLEX_ALLOC_MEM(ent, refname, refname, len);
|
||||||
hashmap_entry_init(&ent->ent, strhash(refname));
|
hashmap_entry_init(&ent->ent, strhash(refname));
|
||||||
oidcpy(&ent->oid, oid);
|
oidcpy(&ent->oid, oid);
|
||||||
hashmap_add(map, ent);
|
hashmap_add(map, &ent->ent);
|
||||||
return ent;
|
return ent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
config.c
2
config.c
@ -1885,7 +1885,7 @@ static int configset_add_value(struct config_set *cs, const char *key, const cha
|
|||||||
hashmap_entry_init(&e->ent, strhash(key));
|
hashmap_entry_init(&e->ent, strhash(key));
|
||||||
e->key = xstrdup(key);
|
e->key = xstrdup(key);
|
||||||
string_list_init(&e->value_list, 1);
|
string_list_init(&e->value_list, 1);
|
||||||
hashmap_add(&cs->config_hash, e);
|
hashmap_add(&cs->config_hash, &e->ent);
|
||||||
}
|
}
|
||||||
si = string_list_append_nodup(&e->value_list, xstrdup_or_null(value));
|
si = string_list_append_nodup(&e->value_list, xstrdup_or_null(value));
|
||||||
|
|
||||||
|
2
diff.c
2
diff.c
@ -1003,7 +1003,7 @@ static void add_lines_to_move_detection(struct diff_options *o,
|
|||||||
if (prev_line && prev_line->es->s == o->emitted_symbols->buf[n].s)
|
if (prev_line && prev_line->es->s == o->emitted_symbols->buf[n].s)
|
||||||
prev_line->next_line = key;
|
prev_line->next_line = key;
|
||||||
|
|
||||||
hashmap_add(hm, key);
|
hashmap_add(hm, &key->ent);
|
||||||
prev_line = key;
|
prev_line = key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -330,7 +330,7 @@ static void insert_file_table(struct repository *r,
|
|||||||
entry->filespec = filespec;
|
entry->filespec = filespec;
|
||||||
|
|
||||||
hashmap_entry_init(&entry->entry, hash_filespec(r, filespec));
|
hashmap_entry_init(&entry->entry, hash_filespec(r, filespec));
|
||||||
hashmap_add(table, entry);
|
hashmap_add(table, &entry->entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -201,12 +201,12 @@ void *hashmap_get_next(const struct hashmap *map,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hashmap_add(struct hashmap *map, void *entry)
|
void hashmap_add(struct hashmap *map, struct hashmap_entry *entry)
|
||||||
{
|
{
|
||||||
unsigned int b = bucket(map, entry);
|
unsigned int b = bucket(map, entry);
|
||||||
|
|
||||||
/* add entry */
|
/* add entry */
|
||||||
((struct hashmap_entry *) entry)->next = map->table[b];
|
entry->next = map->table[b];
|
||||||
map->table[b] = entry;
|
map->table[b] = entry;
|
||||||
|
|
||||||
/* fix size and rehash if appropriate */
|
/* fix size and rehash if appropriate */
|
||||||
@ -302,7 +302,7 @@ const void *memintern(const void *data, size_t len)
|
|||||||
FLEX_ALLOC_MEM(e, data, data, len);
|
FLEX_ALLOC_MEM(e, data, data, len);
|
||||||
hashmap_entry_init(&e->ent, key.ent.hash);
|
hashmap_entry_init(&e->ent, key.ent.hash);
|
||||||
e->len = len;
|
e->len = len;
|
||||||
hashmap_add(&map, e);
|
hashmap_add(&map, &e->ent);
|
||||||
}
|
}
|
||||||
return e->data;
|
return e->data;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
* FLEX_ALLOC_STR(e, value, value);
|
* FLEX_ALLOC_STR(e, value, value);
|
||||||
* hashmap_entry_init(&e->ent, memhash(&key, sizeof(long)));
|
* hashmap_entry_init(&e->ent, memhash(&key, sizeof(long)));
|
||||||
* e->key = key;
|
* e->key = key;
|
||||||
* hashmap_add(&map, e);
|
* hashmap_add(&map, &e->ent);
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* if (!strcmp("print_all_by_key", action)) {
|
* if (!strcmp("print_all_by_key", action)) {
|
||||||
@ -328,7 +328,7 @@ void *hashmap_get_next(const struct hashmap *map,
|
|||||||
* `map` is the hashmap structure.
|
* `map` is the hashmap structure.
|
||||||
* `entry` is the entry to add.
|
* `entry` is the entry to add.
|
||||||
*/
|
*/
|
||||||
void hashmap_add(struct hashmap *map, void *entry);
|
void hashmap_add(struct hashmap *map, struct hashmap_entry *entry);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adds or replaces a hashmap entry. If the hashmap contains duplicate
|
* Adds or replaces a hashmap entry. If the hashmap contains duplicate
|
||||||
|
@ -455,7 +455,7 @@ static int save_files_dirs(const struct object_id *oid,
|
|||||||
|
|
||||||
FLEX_ALLOC_MEM(entry, path, base->buf, base->len);
|
FLEX_ALLOC_MEM(entry, path, base->buf, base->len);
|
||||||
hashmap_entry_init(&entry->e, path_hash(entry->path));
|
hashmap_entry_init(&entry->e, path_hash(entry->path));
|
||||||
hashmap_add(&opt->current_file_dir_set, entry);
|
hashmap_add(&opt->current_file_dir_set, &entry->e);
|
||||||
|
|
||||||
strbuf_setlen(base, baselen);
|
strbuf_setlen(base, baselen);
|
||||||
return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
|
return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
|
||||||
@ -732,7 +732,7 @@ static char *unique_path(struct merge_options *opt, const char *path, const char
|
|||||||
|
|
||||||
FLEX_ALLOC_MEM(entry, path, newpath.buf, newpath.len);
|
FLEX_ALLOC_MEM(entry, path, newpath.buf, newpath.len);
|
||||||
hashmap_entry_init(&entry->e, path_hash(entry->path));
|
hashmap_entry_init(&entry->e, path_hash(entry->path));
|
||||||
hashmap_add(&opt->current_file_dir_set, entry);
|
hashmap_add(&opt->current_file_dir_set, &entry->e);
|
||||||
return strbuf_detach(&newpath, NULL);
|
return strbuf_detach(&newpath, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ static struct dir_entry *hash_dir_entry(struct index_state *istate,
|
|||||||
FLEX_ALLOC_MEM(dir, name, ce->name, namelen);
|
FLEX_ALLOC_MEM(dir, name, ce->name, namelen);
|
||||||
hashmap_entry_init(&dir->ent, memihash(ce->name, namelen));
|
hashmap_entry_init(&dir->ent, memihash(ce->name, namelen));
|
||||||
dir->namelen = namelen;
|
dir->namelen = namelen;
|
||||||
hashmap_add(&istate->dir_hash, dir);
|
hashmap_add(&istate->dir_hash, &dir->ent);
|
||||||
|
|
||||||
/* recursively add missing parent directories */
|
/* recursively add missing parent directories */
|
||||||
dir->parent = hash_dir_entry(istate, ce, namelen);
|
dir->parent = hash_dir_entry(istate, ce, namelen);
|
||||||
@ -107,7 +107,7 @@ static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
|
|||||||
return;
|
return;
|
||||||
ce->ce_flags |= CE_HASHED;
|
ce->ce_flags |= CE_HASHED;
|
||||||
hashmap_entry_init(&ce->ent, memihash(ce->name, ce_namelen(ce)));
|
hashmap_entry_init(&ce->ent, memihash(ce->name, ce_namelen(ce)));
|
||||||
hashmap_add(&istate->name_hash, ce);
|
hashmap_add(&istate->name_hash, &ce->ent);
|
||||||
|
|
||||||
if (ignore_case)
|
if (ignore_case)
|
||||||
add_dir_entry(istate, ce);
|
add_dir_entry(istate, ce);
|
||||||
@ -283,7 +283,7 @@ static struct dir_entry *hash_dir_entry_with_parent_and_prefix(
|
|||||||
hashmap_entry_init(&dir->ent, hash);
|
hashmap_entry_init(&dir->ent, hash);
|
||||||
dir->namelen = prefix->len;
|
dir->namelen = prefix->len;
|
||||||
dir->parent = parent;
|
dir->parent = parent;
|
||||||
hashmap_add(&istate->dir_hash, dir);
|
hashmap_add(&istate->dir_hash, &dir->ent);
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
unlock_dir_mutex(lock_nr);
|
unlock_dir_mutex(lock_nr);
|
||||||
@ -473,7 +473,7 @@ static void *lazy_name_thread_proc(void *_data)
|
|||||||
struct cache_entry *ce_k = d->istate->cache[k];
|
struct cache_entry *ce_k = d->istate->cache[k];
|
||||||
ce_k->ce_flags |= CE_HASHED;
|
ce_k->ce_flags |= CE_HASHED;
|
||||||
hashmap_entry_init(&ce_k->ent, d->lazy_entries[k].hash_name);
|
hashmap_entry_init(&ce_k->ent, d->lazy_entries[k].hash_name);
|
||||||
hashmap_add(&d->istate->name_hash, ce_k);
|
hashmap_add(&d->istate->name_hash, &ce_k->ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1488,7 +1488,7 @@ static void add_delta_base_cache(struct packed_git *p, off_t base_offset,
|
|||||||
if (!delta_base_cache.cmpfn)
|
if (!delta_base_cache.cmpfn)
|
||||||
hashmap_init(&delta_base_cache, delta_base_cache_hash_cmp, NULL, 0);
|
hashmap_init(&delta_base_cache, delta_base_cache_hash_cmp, NULL, 0);
|
||||||
hashmap_entry_init(&ent->ent, pack_entry_hash(p, base_offset));
|
hashmap_entry_init(&ent->ent, pack_entry_hash(p, base_offset));
|
||||||
hashmap_add(&delta_base_cache, ent);
|
hashmap_add(&delta_base_cache, &ent->ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
int packed_object_info(struct repository *r, struct packed_git *p,
|
int packed_object_info(struct repository *r, struct packed_git *p,
|
||||||
|
@ -116,6 +116,6 @@ struct patch_id *add_commit_patch_id(struct commit *commit,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
hashmap_add(&ids->patches, key);
|
hashmap_add(&ids->patches, &key->ent);
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ static void find_exact_matches(struct string_list *a, struct string_list *b)
|
|||||||
util->patch = a->items[i].string;
|
util->patch = a->items[i].string;
|
||||||
util->diff = util->patch + util->diff_offset;
|
util->diff = util->patch + util->diff_offset;
|
||||||
hashmap_entry_init(&util->e, strhash(util->diff));
|
hashmap_entry_init(&util->e, strhash(util->diff));
|
||||||
hashmap_add(&map, util);
|
hashmap_add(&map, &util->e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now try to find exact matches in b */
|
/* Now try to find exact matches in b */
|
||||||
|
@ -1568,7 +1568,7 @@ static void populate_worktree_map(struct hashmap *map, struct worktree **worktre
|
|||||||
hashmap_entry_init(&entry->ent,
|
hashmap_entry_init(&entry->ent,
|
||||||
strhash(worktrees[i]->head_ref));
|
strhash(worktrees[i]->head_ref));
|
||||||
|
|
||||||
hashmap_add(map, entry);
|
hashmap_add(map, &entry->ent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4539,7 +4539,7 @@ static const char *label_oid(struct object_id *oid, const char *label,
|
|||||||
|
|
||||||
FLEX_ALLOC_STR(labels_entry, label, label);
|
FLEX_ALLOC_STR(labels_entry, label, label);
|
||||||
hashmap_entry_init(&labels_entry->entry, strihash(label));
|
hashmap_entry_init(&labels_entry->entry, strihash(label));
|
||||||
hashmap_add(&state->labels, labels_entry);
|
hashmap_add(&state->labels, &labels_entry->entry);
|
||||||
|
|
||||||
FLEX_ALLOC_STR(string_entry, string, label);
|
FLEX_ALLOC_STR(string_entry, string, label);
|
||||||
oidcpy(&string_entry->entry.oid, oid);
|
oidcpy(&string_entry->entry.oid, oid);
|
||||||
|
@ -105,7 +105,7 @@ int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, co
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
hashmap_add(hashmap, entry);
|
hashmap_add(hashmap, &entry->ent);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ static void cache_add(struct submodule_cache *cache,
|
|||||||
struct submodule_entry *e = xmalloc(sizeof(*e));
|
struct submodule_entry *e = xmalloc(sizeof(*e));
|
||||||
hashmap_entry_init(&e->ent, hash);
|
hashmap_entry_init(&e->ent, hash);
|
||||||
e->config = submodule;
|
e->config = submodule;
|
||||||
hashmap_add(&cache->for_name, e);
|
hashmap_add(&cache->for_name, &e->ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct submodule *cache_lookup_path(struct submodule_cache *cache,
|
static const struct submodule *cache_lookup_path(struct submodule_cache *cache,
|
||||||
|
@ -104,7 +104,7 @@ static void perf_hashmap(unsigned int method, unsigned int rounds)
|
|||||||
/* add entries */
|
/* add entries */
|
||||||
for (i = 0; i < TEST_SIZE; i++) {
|
for (i = 0; i < TEST_SIZE; i++) {
|
||||||
hashmap_entry_init(&entries[i]->ent, hashes[i]);
|
hashmap_entry_init(&entries[i]->ent, hashes[i]);
|
||||||
hashmap_add(&map, entries[i]);
|
hashmap_add(&map, &entries[i]->ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
hashmap_free(&map, 0);
|
hashmap_free(&map, 0);
|
||||||
@ -117,7 +117,7 @@ static void perf_hashmap(unsigned int method, unsigned int rounds)
|
|||||||
j = (method & TEST_SPARSE) ? TEST_SIZE / 10 : TEST_SIZE;
|
j = (method & TEST_SPARSE) ? TEST_SIZE / 10 : TEST_SIZE;
|
||||||
for (i = 0; i < j; i++) {
|
for (i = 0; i < j; i++) {
|
||||||
hashmap_entry_init(&entries[i]->ent, hashes[i]);
|
hashmap_entry_init(&entries[i]->ent, hashes[i]);
|
||||||
hashmap_add(&map, entries[i]);
|
hashmap_add(&map, &entries[i]->ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; j < rounds; j++) {
|
for (j = 0; j < rounds; j++) {
|
||||||
@ -179,7 +179,7 @@ int cmd__hashmap(int argc, const char **argv)
|
|||||||
entry = alloc_test_entry(hash, p1, p2);
|
entry = alloc_test_entry(hash, p1, p2);
|
||||||
|
|
||||||
/* add to hashmap */
|
/* add to hashmap */
|
||||||
hashmap_add(&map, entry);
|
hashmap_add(&map, &entry->ent);
|
||||||
|
|
||||||
} else if (!strcmp("put", cmd) && p1 && p2) {
|
} else if (!strcmp("put", cmd) && p1 && p2) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user