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>
maint
Stefan Beller 2017-06-30 17:28:29 -07:00 committed by Junio C Hamano
parent 1ecbf31d02
commit 201c14e375
1 changed files with 7 additions and 5 deletions

12
attr.c
View File

@ -76,18 +76,20 @@ struct attr_hash_entry {
}; };


/* attr_hashmap comparison function */ /* attr_hashmap comparison function */
static int attr_hash_entry_cmp(void *unused_cmp_data, static int attr_hash_entry_cmp(const void *unused_cmp_data,
const struct attr_hash_entry *a, const void *entry,
const struct attr_hash_entry *b, const void *entry_or_key,
void *unused_keydata) const void *unused_keydata)
{ {
const struct attr_hash_entry *a = entry;
const struct attr_hash_entry *b = entry_or_key;
return (a->keylen != b->keylen) || strncmp(a->key, b->key, a->keylen); return (a->keylen != b->keylen) || strncmp(a->key, b->key, a->keylen);
} }


/* Initialize an 'attr_hashmap' object */ /* Initialize an 'attr_hashmap' object */
static void attr_hashmap_init(struct attr_hashmap *map) static void attr_hashmap_init(struct attr_hashmap *map)
{ {
hashmap_init(&map->map, (hashmap_cmp_fn) attr_hash_entry_cmp, NULL, 0); hashmap_init(&map->map, attr_hash_entry_cmp, NULL, 0);
} }


/* /*