convert hashmap comparison functions to oideq()
The comparison functions used for hashmaps don't care about strict ordering; they only want to compare entries for equality. Let's use the oideq() function instead, which can potentially be better optimized. Note that unlike the previous patches mass-converting calls like "!oidcmp()", this patch could actually provide an improvement even with the current implementation. Those comparison functions are passed around as function pointers, so at compile-time the compiler cannot realize that the caller (which is in another file completely) will treat the return value as a boolean. Note that this does change the return values in quite a subtle way (it's still an int, but now the sign bit is irrelevant for ordering). Because of their funny hashmap-specific signature, it's unlikely that any of these static functions would be reused for more generic ordering. But to be double-sure, let's stop using "cmp" in their names. Calling them "eq" doesn't quite work either, because the hashmap convention is actually _inverted_. "0" means "same", and non-zero means "different". So I've called them "neq" by convention here. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
67947c34ae
commit
cc00e5ce6b
12
oidmap.c
12
oidmap.c
@ -1,14 +1,14 @@
|
||||
#include "cache.h"
|
||||
#include "oidmap.h"
|
||||
|
||||
static int cmpfn(const void *hashmap_cmp_fn_data,
|
||||
const void *entry, const void *entry_or_key,
|
||||
const void *keydata)
|
||||
static int oidmap_neq(const void *hashmap_cmp_fn_data,
|
||||
const void *entry, const void *entry_or_key,
|
||||
const void *keydata)
|
||||
{
|
||||
const struct oidmap_entry *entry_ = entry;
|
||||
if (keydata)
|
||||
return oidcmp(&entry_->oid, (const struct object_id *) keydata);
|
||||
return oidcmp(&entry_->oid,
|
||||
return !oideq(&entry_->oid, (const struct object_id *) keydata);
|
||||
return !oideq(&entry_->oid,
|
||||
&((const struct oidmap_entry *) entry_or_key)->oid);
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ static int hash(const struct object_id *oid)
|
||||
|
||||
void oidmap_init(struct oidmap *map, size_t initial_size)
|
||||
{
|
||||
hashmap_init(&map->map, cmpfn, NULL, initial_size);
|
||||
hashmap_init(&map->map, oidmap_neq, NULL, initial_size);
|
||||
}
|
||||
|
||||
void oidmap_free(struct oidmap *map, int free_entries)
|
||||
|
Reference in New Issue
Block a user