summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>2016-10-14 15:37:07 +0100
committerDaniele Di Proietto <diproiettod@vmware.com>2016-10-17 18:32:40 -0700
commita17408e432b7faba04219f48f00f8067010b8aed (patch)
treeaacff2aaf4f6aeca01f950d21739ffcc207fa5ab /lib
parent5c8f8763604972318a392ae83340e43bc41cf1f1 (diff)
downloadopenvswitch-a17408e432b7faba04219f48f00f8067010b8aed.tar.gz
hash: Skip Invoking mhash_add__() with zero input.
mhash_add__() is expensive and should be only called with valid input. zero-valued 'data' will not affect the 'hash' value and expensive hash computation can be skipped when input is zero. This patch will validate the input in mhash_add__ to save some cpu cycles. Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com> Co-authored-by: Antonio Fischetti <antonio.fischetti@intel.com> Signed-off-by: Antonio Fischetti <antonio.fischetti@intel.com> Acked-by: Daniele Di Proietto <diproiettod@vmware.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/hash.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/hash.h b/lib/hash.h
index 114a41999..f2dd51024 100644
--- a/lib/hash.h
+++ b/lib/hash.h
@@ -62,6 +62,11 @@ static inline uint32_t hash_string(const char *, uint32_t basis);
static inline uint32_t mhash_add__(uint32_t hash, uint32_t data)
{
+ /* zero-valued 'data' will not change the 'hash' value */
+ if (!data) {
+ return hash;
+ }
+
data *= 0xcc9e2d51;
data = hash_rot(data, 15);
data *= 0x1b873593;