From b690304eed4c81c9889a6bf9c4c3edd37d228bb5 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 26 Feb 2021 16:53:06 -0800 Subject: [PATCH] use faster way for siphash (#11640) --- cmd/erasure-sets.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/erasure-sets.go b/cmd/erasure-sets.go index 0d54d0370..71731a00c 100644 --- a/cmd/erasure-sets.go +++ b/cmd/erasure-sets.go @@ -18,6 +18,7 @@ package cmd import ( "context" + "encoding/binary" "errors" "fmt" "hash/crc32" @@ -663,9 +664,11 @@ func sipHashMod(key string, cardinality int, id [16]byte) int { if cardinality <= 0 { return -1 } - sip := siphash.New(id[:]) - sip.Write([]byte(key)) - return int(sip.Sum64() % uint64(cardinality)) + // use the faster version as per siphash docs + // https://github.com/dchest/siphash#usage + k0, k1 := binary.LittleEndian.Uint64(id[0:8]), binary.LittleEndian.Uint64(id[8:16]) + sum64 := siphash.Hash(k0, k1, []byte(key)) + return int(sum64 % uint64(cardinality)) } func crcHashMod(key string, cardinality int) int {