lib: Allow hash_get to sidestep expensive hash key generation in some cases

There is no need to generate a hash key *if* the hash_alloc_function
is NULL and the hash is empty.

This changed showed a measurable increase in performance for
table hash lookup for tables that were meant to be empty in
bgp( the distance commands ).

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
Donald Sharp 2017-10-16 13:56:01 -04:00
parent 4c6ed05e4e
commit efb149d95b

View file

@ -143,6 +143,9 @@ void *hash_get(struct hash *hash, void *data, void *(*alloc_func)(void *))
void *newdata;
struct hash_backet *backet;
if (!alloc_func && !hash->count)
return NULL;
key = (*hash->hash_key)(data);
index = key & (hash->size - 1);