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

Jarno Rajahalme jarno at ovn.org
Fri Oct 7 21:09:19 UTC 2016


> On Oct 7, 2016, at 9:17 AM, Bhanuprakash Bodireddy <bhanuprakash.bodireddy at intel.com> wrote:
> 
> 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;

IMO the zero check is best placed in the function mhash_add__(), where it is also more evident that zero-valued data would not change the hash anyway. Maybe a comment to that effect would be also nice?

>     hash = hash_rot(hash, 13);
>     return hash * 5 + 0xe6546b64;
> }
> -- 
> 2.4.11
> 
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev




More information about the dev mailing list