mirror of
https://github.com/rclone/rclone.git
synced 2024-11-30 04:15:26 +01:00
dc5d5de35c
This commits ports a fast C-implementation from https://github.com/namazso/QuickXorHash It uses new crypto/subtle code from go1.20 to avoid the use of unsafe. Typical speedups are about 25x when using go1.20 goos: linux goarch: amd64 cpu: Intel(R) Celeron(R) N5105 @ 2.00GHz QuickXorHash-Before 2.49ms 422MB/s ±11% 100.00% QuickXorHash-Subtle 87.9µs 11932MB/s ± 5% +2730.83% + 42.17% Co-Author: @namazso
21 lines
299 B
Go
21 lines
299 B
Go
//go:build !go1.20
|
|
|
|
package quickxorhash
|
|
|
|
func xorBytes(dst, src []byte) int {
|
|
n := len(dst)
|
|
if len(src) < n {
|
|
n = len(src)
|
|
}
|
|
if n == 0 {
|
|
return 0
|
|
}
|
|
dst = dst[:n]
|
|
//src = src[:n]
|
|
src = src[:len(dst)] // remove bounds check in loop
|
|
for i := range dst {
|
|
dst[i] ^= src[i]
|
|
}
|
|
return n
|
|
}
|