From 1f10b4026d57d906e1164b751e1910fa68114d5b Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Wed, 7 Aug 2019 20:52:31 -0300 Subject: [PATCH] inline hash function to save extra alloc (#53) --- internal/utils.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/internal/utils.go b/internal/utils.go index ca365fd..07e814c 100644 --- a/internal/utils.go +++ b/internal/utils.go @@ -2,7 +2,6 @@ package internal import ( "fmt" - "hash/fnv" "os" "path/filepath" "sort" @@ -10,10 +9,18 @@ import ( "strings" ) +const ( + offset64 = 14695981039346656037 + prime64 = 1099511628211 +) + func Hash(key []byte) uint64 { - h := fnv.New64a() - h.Write(key) - return h.Sum64() + var s uint64 = offset64 + for _, c := range key { + s ^= uint64(c) + s *= prime64 + } + return s } func Exists(path string) bool {