]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Allow hash_get to sidestep expensive hash key generation in some cases
authorDonald Sharp <sharpd@cumulusnetworks.com>
Mon, 16 Oct 2017 17:56:01 +0000 (13:56 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Mon, 16 Oct 2017 17:56:01 +0000 (13:56 -0400)
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>
lib/hash.c

index d2846d7379bcf3f60c7dc2bfbd00e212536d3079..f222279216a6f590fa6aeccd789d523cddcbac3c 100644 (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);