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.bodire...@intel.com>
Co-authored-by: Antonio Fischetti <antonio.fische...@intel.com>
Signed-off-by: Antonio Fischetti <antonio.fische...@intel.com>
---
lib/hash.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/lib/hash.h b/lib/hash.h
index 114a419..f2dd510 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;
--
2.4.11
_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev