@@ -42,10 +42,10 @@ const (
42
42
baseMatchLength = 3 // The smallest match length per the RFC section 3.2.5
43
43
maxMatchOffset = 1 << 15 // The largest match offset
44
44
45
- bTableBits = 18 // Bits used in the big tables
46
- bTableSize = 1 << bTableBits // Size of the table
47
- allocHistory = maxMatchOffset * 10 // Size to preallocate for history.
48
- bufferReset = (1 << 31 ) - allocHistory - maxStoreBlockSize // Reset the buffer offset when reaching this.
45
+ bTableBits = 18 // Bits used in the big tables
46
+ bTableSize = 1 << bTableBits // Size of the table
47
+ allocHistory = maxStoreBlockSize * 20 // Size to preallocate for history.
48
+ bufferReset = (1 << 31 ) - allocHistory - maxStoreBlockSize - 1 // Reset the buffer offset when reaching this.
49
49
)
50
50
51
51
const (
@@ -210,16 +210,14 @@ func (e *fastGen) matchlenLong(s, t int32, src []byte) int32 {
210
210
211
211
// Reset the encoding table.
212
212
func (e * fastGen ) Reset () {
213
- if cap (e .hist ) < int ( maxMatchOffset * 8 ) {
214
- l := maxMatchOffset * 8
215
- // Make it at least 1MB.
216
- if l < 1 << 20 {
217
- l = 1 << 20
218
- }
219
- e .hist = make ([] byte , 0 , l )
213
+ if cap (e .hist ) < allocHistory {
214
+ e . hist = make ([] byte , 0 , allocHistory )
215
+ }
216
+ // We offset current position so everything will be out of reach.
217
+ // If we are above the buffer reset it will be cleared anyway since len(hist) == 0.
218
+ if e . cur <= bufferReset {
219
+ e .cur += maxMatchOffset + int32 ( len ( e . hist ) )
220
220
}
221
- // We offset current position so everything will be out of reach
222
- e .cur += maxMatchOffset + int32 (len (e .hist ))
223
221
e .hist = e .hist [:0 ]
224
222
}
225
223
0 commit comments