summaryrefslogtreecommitdiff
path: root/hashmap.h
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-10-06 23:30:27 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-10-07 01:20:09 (GMT)
commitd22245a2e360d2e708ca37169be8eb5a5899b98d (patch)
treef1bde8f5da6ea424fa1f9538d6debd4b5fd6b5f4 /hashmap.h
parentd0a48a0a1d0df49af2e5fd6a80b0d84776c285aa (diff)
downloadgit-d22245a2e360d2e708ca37169be8eb5a5899b98d.zip
git-d22245a2e360d2e708ca37169be8eb5a5899b98d.tar.gz
git-d22245a2e360d2e708ca37169be8eb5a5899b98d.tar.bz2
hashmap_entry_init takes "struct hashmap_entry *"
C compilers do type checking to make life easier for us. So rely on that and update all hashmap_entry_init callers to take "struct hashmap_entry *" to avoid future bugs while improving safety and readability. Signed-off-by: Eric Wong <e@80x24.org> Reviewed-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'hashmap.h')
-rw-r--r--hashmap.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/hashmap.h b/hashmap.h
index 8424911..54b0b8c 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -48,14 +48,14 @@
* if (!strcmp("add", action)) {
* struct long2string *e;
* FLEX_ALLOC_STR(e, value, value);
- * hashmap_entry_init(e, memhash(&key, sizeof(long)));
+ * hashmap_entry_init(&e->ent, memhash(&key, sizeof(long)));
* e->key = key;
* hashmap_add(&map, e);
* }
*
* if (!strcmp("print_all_by_key", action)) {
* struct long2string k, *e;
- * hashmap_entry_init(&k, memhash(&key, sizeof(long)));
+ * hashmap_entry_init(&k->ent, memhash(&key, sizeof(long)));
* k.key = key;
*
* flags &= ~COMPARE_VALUE;
@@ -70,7 +70,7 @@
* if (!strcmp("has_exact_match", action)) {
* struct long2string *e;
* FLEX_ALLOC_STR(e, value, value);
- * hashmap_entry_init(e, memhash(&key, sizeof(long)));
+ * hashmap_entry_init(&e->ent, memhash(&key, sizeof(long)));
* e->key = key;
*
* flags |= COMPARE_VALUE;
@@ -80,7 +80,7 @@
*
* if (!strcmp("has_exact_match_no_heap_alloc", action)) {
* struct long2string k;
- * hashmap_entry_init(&k, memhash(&key, sizeof(long)));
+ * hashmap_entry_init(&k->ent, memhash(&key, sizeof(long)));
* k.key = key;
*
* flags |= COMPARE_VALUE;
@@ -244,9 +244,9 @@ void hashmap_free(struct hashmap *map, int free_entries);
* your structure was allocated with xmalloc(), you can just free(3) it,
* and if it is on stack, you can just let it go out of scope).
*/
-static inline void hashmap_entry_init(void *entry, unsigned int hash)
+static inline void hashmap_entry_init(struct hashmap_entry *e,
+ unsigned int hash)
{
- struct hashmap_entry *e = entry;
e->hash = hash;
e->next = NULL;
}