Skip to content

Commit b94e5c1

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

20 files changed

+31
-31
lines changed

attr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static void attr_hashmap_add(struct attr_hashmap *map,
122122
e->keylen = keylen;
123123
e->value = value;
124124

125-
hashmap_add(&map->map, e);
125+
hashmap_add(&map->map, &e->ent);
126126
}
127127

128128
struct all_attrs_item {

blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ static void get_fingerprint(struct fingerprint *result,
424424
found_entry->count += 1;
425425
} else {
426426
entry->count = 1;
427-
hashmap_add(&result->map, entry);
427+
hashmap_add(&result->map, &entry->entry);
428428
++entry;
429429
}
430430
}

builtin/describe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static void add_to_known_names(const char *path,
124124
e = xmalloc(sizeof(struct commit_name));
125125
oidcpy(&e->peeled, peeled);
126126
hashmap_entry_init(&e->entry, oidhash(peeled));
127-
hashmap_add(&names, e);
127+
hashmap_add(&names, &e->entry);
128128
e->path = NULL;
129129
}
130130
e->tag = tag;

builtin/difftool.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static void add_left_or_right(struct hashmap *map, const char *path,
168168
e = existing;
169169
} else {
170170
e->left[0] = e->right[0] = '\0';
171-
hashmap_add(map, e);
171+
hashmap_add(map, &e->entry);
172172
}
173173
strlcpy(is_right ? e->right : e->left, content, PATH_MAX);
174174
}
@@ -235,7 +235,7 @@ static void changed_files(struct hashmap *result, const char *index_path,
235235
struct path_entry *entry;
236236
FLEX_ALLOC_STR(entry, path, buf.buf);
237237
hashmap_entry_init(&entry->entry, strhash(buf.buf));
238-
hashmap_add(result, entry);
238+
hashmap_add(result, &entry->entry);
239239
}
240240
fclose(fp);
241241
if (finish_command(&diff_files))
@@ -466,7 +466,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
466466
free(entry);
467467
continue;
468468
}
469-
hashmap_add(&working_tree_dups, entry);
469+
hashmap_add(&working_tree_dups, &entry->entry);
470470

471471
if (!use_wt_file(workdir, dst_path, &roid)) {
472472
if (checkout_path(rmode, &roid, dst_path,

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ static struct refname_hash_entry *refname_hash_add(struct hashmap *map,
278278
FLEX_ALLOC_MEM(ent, refname, refname, len);
279279
hashmap_entry_init(&ent->ent, strhash(refname));
280280
oidcpy(&ent->oid, oid);
281-
hashmap_add(map, ent);
281+
hashmap_add(map, &ent->ent);
282282
return ent;
283283
}
284284

config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,7 @@ static int configset_add_value(struct config_set *cs, const char *key, const cha
18851885
hashmap_entry_init(&e->ent, strhash(key));
18861886
e->key = xstrdup(key);
18871887
string_list_init(&e->value_list, 1);
1888-
hashmap_add(&cs->config_hash, e);
1888+
hashmap_add(&cs->config_hash, &e->ent);
18891889
}
18901890
si = string_list_append_nodup(&e->value_list, xstrdup_or_null(value));
18911891

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ static void add_lines_to_move_detection(struct diff_options *o,
10031003
if (prev_line && prev_line->es->s == o->emitted_symbols->buf[n].s)
10041004
prev_line->next_line = key;
10051005

1006-
hashmap_add(hm, key);
1006+
hashmap_add(hm, &key->ent);
10071007
prev_line = key;
10081008
}
10091009
}

diffcore-rename.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ static void insert_file_table(struct repository *r,
330330
entry->filespec = filespec;
331331

332332
hashmap_entry_init(&entry->entry, hash_filespec(r, filespec));
333-
hashmap_add(table, entry);
333+
hashmap_add(table, &entry->entry);
334334
}
335335

336336
/*

hashmap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ void *hashmap_get_next(const struct hashmap *map,
201201
return NULL;
202202
}
203203

204-
void hashmap_add(struct hashmap *map, void *entry)
204+
void hashmap_add(struct hashmap *map, struct hashmap_entry *entry)
205205
{
206206
unsigned int b = bucket(map, entry);
207207

208208
/* add entry */
209-
((struct hashmap_entry *) entry)->next = map->table[b];
209+
entry->next = map->table[b];
210210
map->table[b] = entry;
211211

212212
/* fix size and rehash if appropriate */
@@ -302,7 +302,7 @@ const void *memintern(const void *data, size_t len)
302302
FLEX_ALLOC_MEM(e, data, data, len);
303303
hashmap_entry_init(&e->ent, key.ent.hash);
304304
e->len = len;
305-
hashmap_add(&map, e);
305+
hashmap_add(&map, &e->ent);
306306
}
307307
return e->data;
308308
}

hashmap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* FLEX_ALLOC_STR(e, value, value);
5151
* hashmap_entry_init(&e->ent, memhash(&key, sizeof(long)));
5252
* e->key = key;
53-
* hashmap_add(&map, e);
53+
* hashmap_add(&map, &e->ent);
5454
* }
5555
*
5656
* if (!strcmp("print_all_by_key", action)) {
@@ -328,7 +328,7 @@ void *hashmap_get_next(const struct hashmap *map,
328328
* `map` is the hashmap structure.
329329
* `entry` is the entry to add.
330330
*/
331-
void hashmap_add(struct hashmap *map, void *entry);
331+
void hashmap_add(struct hashmap *map, struct hashmap_entry *entry);
332332

333333
/*
334334
* Adds or replaces a hashmap entry. If the hashmap contains duplicate

0 commit comments

Comments
 (0)