2024-08-19 12:13:46 +02:00
|
|
|
//go:build !amd64 || appengine || !gc || noasm
|
|
|
|
// +build !amd64 appengine !gc noasm
|
|
|
|
|
|
|
|
// Copyright 2019+ Klaus Post. All rights reserved.
|
|
|
|
// License information can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package zstd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/bits"
|
2025-03-02 16:42:51 +01:00
|
|
|
|
|
|
|
"github.com/klauspost/compress/internal/le"
|
2024-08-19 12:13:46 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// matchLen returns the maximum common prefix length of a and b.
|
|
|
|
// a must be the shortest of the two.
|
|
|
|
func matchLen(a, b []byte) (n int) {
|
2025-03-02 16:42:51 +01:00
|
|
|
left := len(a)
|
|
|
|
for left >= 8 {
|
|
|
|
diff := le.Load64(a, n) ^ le.Load64(b, n)
|
2024-08-19 12:13:46 +02:00
|
|
|
if diff != 0 {
|
|
|
|
return n + bits.TrailingZeros64(diff)>>3
|
|
|
|
}
|
|
|
|
n += 8
|
2025-03-02 16:42:51 +01:00
|
|
|
left -= 8
|
2024-08-19 12:13:46 +02:00
|
|
|
}
|
2025-03-02 16:42:51 +01:00
|
|
|
a = a[n:]
|
|
|
|
b = b[n:]
|
2024-08-19 12:13:46 +02:00
|
|
|
|
|
|
|
for i := range a {
|
|
|
|
if a[i] != b[i] {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
n++
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
|
|
|
|
}
|