Debian Codegraph @

zstd/matchlen_generic.go

raw
1 //go:build !amd64 || appengine || !gc || noasm
2
3 // Copyright 2019+ Klaus Post. All rights reserved.
4 // License information can be found in the LICENSE file.
5
6 package zstd
7
8 import (
9 "math/bits"
10
11 "github.com/klauspost/compress/internal/le"
12 )
13
14 // matchLen returns the maximum common prefix length of a and b.
15 // a must be the shortest of the two.
16 func matchLen(a, b []byte) (n int) {
17 left := len(a)
18 for left >= 8 {
19 diff := le.Load64(a, n) ^ le.Load64(b, n)
20 if diff != 0 {
21 return n + bits.TrailingZeros64(diff)>>3
22 }
23 n += 8
24 left -= 8
25 }
26 a = a[n:]
27 b = b[n:]
28
29 for i := range a {
30 if a[i] != b[i] {
31 break
32 }
33 n++
34 }
35 return n
36
37 }