[ovs-dev] [PATCH 04/12] hash: Skip invoking mhash_add__() with zero input.

Bhanuprakash Bodireddy bhanuprakash.bodireddy at intel.com
Fri Oct 7 16:17:34 UTC 2016


mhash_add__() is expensive and should be only called with valid input.
This patch will validate the input before invoking the mhash_add__ and
there by saving some cpu cycles.

Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy at intel.com>
Signed-off-by: Antonio Fischetti <antonio.fischetti at intel.com>
---
 lib/hash.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/hash.h b/lib/hash.h
index 114a419..9bfebdb 100644
--- a/lib/hash.h
+++ b/lib/hash.h
@@ -70,7 +70,7 @@ static inline uint32_t mhash_add__(uint32_t hash, uint32_t data)
 
 static inline uint32_t mhash_add(uint32_t hash, uint32_t data)
 {
-    hash = mhash_add__(hash, data);
+    hash = data ? mhash_add__(hash, data): hash;
     hash = hash_rot(hash, 13);
     return hash * 5 + 0xe6546b64;
 }
-- 
2.4.11




More information about the dev mailing list