diff options
| author | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-10-16 13:56:01 -0400 |
|---|---|---|
| committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-10-16 13:56:01 -0400 |
| commit | efb149d95bb4045f44fcaf6e9f1d59f76af6c013 (patch) | |
| tree | 93d52158ce587c596a255ca8fac1ad77bec7ce5c /lib/hash.c | |
| parent | 4c6ed05e4e2276c463f16c1dbf8d9f04bc1130fe (diff) | |
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>
Diffstat (limited to 'lib/hash.c')
| -rw-r--r-- | lib/hash.c | 3 |
1 files changed, 3 insertions, 0 deletions
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); |
