aboutsummaryrefslogtreecommitdiffhomepage
path: root/helpers
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-07-30 12:52:54 +0200
committerBjørn Erik Pedersen <[email protected]>2024-07-31 16:44:06 +0200
commitd5eda13cb2e57998210b66e080dc96e95b38e5f0 (patch)
treeb52bc254cf9d6dcb768a491d73c725d7104dd9cd /helpers
parent8b5d796989cf0798ee61003159ba8b332675bdf2 (diff)
downloadhugo-d5eda13cb2e57998210b66e080dc96e95b38e5f0.tar.gz
hugo-d5eda13cb2e57998210b66e080dc96e95b38e5f0.zip
Replace the MD5 hashing of images with xxHash
Note that we only use this for change detection. The previous implementation invoked `MD5FromReaderFast` that created a MD5 has from 8 64 bytes chunks in the file, which is obviously very fast. The new implementation creates the hash from the entire file and ... seems to be even more effective: ``` name old time/op new time/op delta HashImage-10 9.45µs ±21% 10.89µs ± 1% ~ (p=0.343 n=4+4) name old alloc/op new alloc/op delta HashImage-10 144B ± 0% 8B ± 0% -94.44% (p=0.029 n=4+4) name old allocs/op new allocs/op delta HashImage-10 4.00 ± 0% 1.00 ± 0% -75.00% (p=0.029 n=4+4) ```
Diffstat (limited to 'helpers')
-rw-r--r--helpers/general.go13
1 files changed, 3 insertions, 10 deletions
diff --git a/helpers/general.go b/helpers/general.go
index fa65265b8..a294455dd 100644
--- a/helpers/general.go
+++ b/helpers/general.go
@@ -27,12 +27,11 @@ import (
"unicode"
"unicode/utf8"
- "github.com/cespare/xxhash/v2"
+ bp "github.com/gohugoio/hugo/bufferpool"
+
"github.com/spf13/afero"
"github.com/jdkato/prose/transform"
-
- bp "github.com/gohugoio/hugo/bufferpool"
)
// FilePathSeparator as defined by os.Separator.
@@ -258,13 +257,7 @@ func SliceToLower(s []string) []string {
return l
}
-// XxHashString takes a string and returns its xxHash hash.
-func XxHashString(f string) string {
- h := xxhash.New()
- h.WriteString(f)
- hash := h.Sum(nil)
- return hex.EncodeToString(hash)
-}
+// XXHashFromReader creates a xxHash hash from the given reader.
// MD5String takes a string and returns its MD5 hash.
func MD5String(f string) string {