From efb149d95bb4045f44fcaf6e9f1d59f76af6c013 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 16 Oct 2017 13:56:01 -0400 Subject: [PATCH] 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 --- lib/hash.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/hash.c b/lib/hash.c index d2846d7379..f222279216 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -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); -- 2.39.5