Skip to content

Commit e0f89a9

Browse files
authored
flate: Fix matchlen L5+L6 (#1049)
* flate: Fix matchlen L5+L6 Regression from #1045
1 parent c8a8470 commit e0f89a9

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

flate/fast_encoder.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func hashLen(u uint64, length, mls uint8) uint32 {
137137
// The maximum length returned is maxMatchLength - 4.
138138
// It is assumed that s > t, that t >=0 and s < len(src).
139139
func (e *fastGen) matchlen(s, t int32, src []byte) int32 {
140-
if debugDecode {
140+
if debugDeflate {
141141
if t >= s {
142142
panic(fmt.Sprint("t >=s:", t, s))
143143
}
@@ -151,20 +151,17 @@ func (e *fastGen) matchlen(s, t int32, src []byte) int32 {
151151
panic(fmt.Sprint(s, "-", t, "(", s-t, ") > maxMatchLength (", maxMatchOffset, ")"))
152152
}
153153
}
154-
s1 := int32(s) + maxMatchLength - 4
155-
if s1 > int32(len(src)) {
156-
s1 = int32(len(src))
157-
}
158-
154+
s1 := min(s+maxMatchLength-4, int32(len(src)))
159155
left := s1 - s
160-
n := 0
156+
n := int32(0)
161157
for left >= 8 {
162158
diff := le.Load64(src, s) ^ le.Load64(src, t)
163159
if diff != 0 {
164-
return int32(n + bits.TrailingZeros64(diff)>>3)
160+
return n + int32(bits.TrailingZeros64(diff)>>3)
165161
}
166162
s += 8
167163
t += 8
164+
n += 8
168165
left -= 8
169166
}
170167

@@ -176,8 +173,7 @@ func (e *fastGen) matchlen(s, t int32, src []byte) int32 {
176173
}
177174
n++
178175
}
179-
return int32(n)
180-
// Extend the match to be as long as possible.
176+
return n
181177
}
182178

183179
// matchlenLong will return the match length between offsets and t in src.

0 commit comments

Comments
 (0)