Skip to content

Commit

Permalink
Remove 4 length match check. (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
klauspost committed Sep 2, 2021
1 parent c608412 commit 00a2d6d
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions flate/fast_encoder.go
Expand Up @@ -215,24 +215,15 @@ func (e *fastGen) Reset() {
func matchLen(a, b []byte) int {
b = b[:len(a)]
var checked int
if len(a) >= 4 {
// Try 4 bytes first
if diff := binary.LittleEndian.Uint32(a) ^ binary.LittleEndian.Uint32(b); diff != 0 {
return bits.TrailingZeros32(diff) >> 3
}
// Switch to 8 byte matching.
checked = 4
a = a[4:]
b = b[4:]
for len(a) >= 8 {
b = b[:len(a)]
if diff := binary.LittleEndian.Uint64(a) ^ binary.LittleEndian.Uint64(b); diff != 0 {
return checked + (bits.TrailingZeros64(diff) >> 3)
}
checked += 8
a = a[8:]
b = b[8:]

for len(a) >= 8 {
b = b[:len(a)]
if diff := binary.LittleEndian.Uint64(a) ^ binary.LittleEndian.Uint64(b); diff != 0 {
return checked + (bits.TrailingZeros64(diff) >> 3)
}
checked += 8
a = a[8:]
b = b[8:]
}
b = b[:len(a)]
for i := range a {
Expand Down

0 comments on commit 00a2d6d

Please sign in to comment.