1 //go:build !amd64 || appengine || !gc || noasm 2 // +build !amd64 appengine !gc noasm 3 4 // Copyright 2019+ Klaus Post. All rights reserved. 5 // License information can be found in the LICENSE file. 6 7 package flate 8 9 import ( 10 "encoding/binary" 11 "math/bits" 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 for ; len(a) >= 8 && len(b) >= 8; a, b = a[8:], b[8:] { 18 diff := binary.LittleEndian.Uint64(a) ^ binary.LittleEndian.Uint64(b) 19 if diff != 0 { 20 return n + bits.TrailingZeros64(diff)>>3 21 } 22 n += 8 23 } 24 25 for i := range a { 26 if a[i] != b[i] { 27 break 28 } 29 n++ 30 } 31 return n 32 33 } 34