From 458a5631b4e856977449401d76be563779ed32fc Mon Sep 17 00:00:00 2001 From: apocelipes Date: Fri, 22 Nov 2024 20:10:47 +0800 Subject: [PATCH] Optimize the murmur2 hash function --- balancer.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/balancer.go b/balancer.go index ee3a2588..eb115e9f 100644 --- a/balancer.go +++ b/balancer.go @@ -333,14 +333,14 @@ func murmur2(data []byte) uint32 { } // Handle the last few bytes of the input array - extra := length % 4 - if extra >= 3 { + switch length % 4 { + case 3: h ^= (uint32(data[(length & ^3)+2]) & 0xff) << 16 - } - if extra >= 2 { + fallthrough + case 2: h ^= (uint32(data[(length & ^3)+1]) & 0xff) << 8 - } - if extra >= 1 { + fallthrough + case 1: h ^= uint32(data[length & ^3]) & 0xff h *= m }