attr.c: drop hashmap_cmp_fn cast
MAke the code more readable and less error prone by avoiding the cast of the compare function pointer in hashmap_init, but instead have the correctly named void pointers to casted to the specific data structure. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Jun 30, 2017 at 17:28 UTC
201c14e375bfc0b81c6d7e12d1bae3ba22ce8038
1 file changed
+7
-5
attr.c
+7
-5
@@ -76,18 +76,20 @@ struct attr_hash_entry {
76
};
77
78
/* attr_hashmap comparison function */
79
-static int attr_hash_entry_cmp(void *unused_cmp_data,
80
- const struct attr_hash_entry *a,
81
- const struct attr_hash_entry *b,
82
- void *unused_keydata)
79
+static int attr_hash_entry_cmp(const void *unused_cmp_data,
80
+ const void *entry,
81
+ const void *entry_or_key,
82
+ const void *unused_keydata)
83
{
84
+ const struct attr_hash_entry *a = entry;
85
+ const struct attr_hash_entry *b = entry_or_key;
86
return (a->keylen != b->keylen) || strncmp(a->key, b->key, a->keylen);
87
}
88
89
/* Initialize an 'attr_hashmap' object */
90
static void attr_hashmap_init(struct attr_hashmap *map)
91
{
90
- hashmap_init(&map->map, (hashmap_cmp_fn) attr_hash_entry_cmp, NULL, 0);
92
+ hashmap_init(&map->map, attr_hash_entry_cmp, NULL, 0);
93
}
94
95
/*