Debian Codegraph @

flate/matchlen_generic.go

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