@@ -234,12 +234,9 @@ func (d *compressor) fillWindow(b []byte) {
234234
235235 // Calculate 256 hashes at the time (more L1 cache hits)
236236 loops := (n + 256 - minMatchLength ) / 256
237- for j := 0 ; j < loops ; j ++ {
237+ for j := range loops {
238238 startindex := j * 256
239- end := startindex + 256 + minMatchLength - 1
240- if end > n {
241- end = n
242- }
239+ end := min (startindex + 256 + minMatchLength - 1 , n )
243240 tocheck := d .window [startindex :end ]
244241 dstSize := len (tocheck ) - minMatchLength + 1
245242
@@ -269,29 +266,20 @@ func (d *compressor) fillWindow(b []byte) {
269266// We only look at chainCount possibilities before giving up.
270267// pos = s.index, prevHead = s.chainHead-s.hashOffset, prevLength=minMatchLength-1, lookahead
271268func (d * compressor ) findMatch (pos int , prevHead int , lookahead int ) (length , offset int , ok bool ) {
272- minMatchLook := maxMatchLength
273- if lookahead < minMatchLook {
274- minMatchLook = lookahead
275- }
269+ minMatchLook := min (lookahead , maxMatchLength )
276270
277271 win := d .window [0 : pos + minMatchLook ]
278272
279273 // We quit when we get a match that's at least nice long
280- nice := len (win ) - pos
281- if d .nice < nice {
282- nice = d .nice
283- }
274+ nice := min (d .nice , len (win )- pos )
284275
285276 // If we've got a match that's good enough, only look in 1/4 the chain.
286277 tries := d .chain
287278 length = minMatchLength - 1
288279
289280 wEnd := win [pos + length ]
290281 wPos := win [pos :]
291- minIndex := pos - windowSize
292- if minIndex < 0 {
293- minIndex = 0
294- }
282+ minIndex := max (pos - windowSize , 0 )
295283 offset = 0
296284
297285 if d .chain < 100 {
@@ -480,10 +468,7 @@ func (d *compressor) deflateLazy() {
480468 prevOffset := s .offset
481469 s .length = minMatchLength - 1
482470 s .offset = 0
483- minIndex := s .index - windowSize
484- if minIndex < 0 {
485- minIndex = 0
486- }
471+ minIndex := max (s .index - windowSize , 0 )
487472
488473 if s .chainHead - s .hashOffset >= minIndex && lookahead > prevLength && prevLength < d .lazy {
489474 if newLength , newOffset , ok := d .findMatch (s .index , s .chainHead - s .hashOffset , lookahead ); ok {
@@ -503,10 +488,7 @@ func (d *compressor) deflateLazy() {
503488 if prevLength < maxMatchLength - checkOff {
504489 prevIndex := s .index - 1
505490 if prevIndex + prevLength < s .maxInsertIndex {
506- end := lookahead
507- if lookahead > maxMatchLength + checkOff {
508- end = maxMatchLength + checkOff
509- }
491+ end := min (lookahead , maxMatchLength + checkOff )
510492 end += prevIndex
511493
512494 // Hash at match end.
@@ -603,15 +585,9 @@ func (d *compressor) deflateLazy() {
603585 // table.
604586 newIndex := s .index + prevLength - 1
605587 // Calculate missing hashes
606- end := newIndex
607- if end > s .maxInsertIndex {
608- end = s .maxInsertIndex
609- }
588+ end := min (newIndex , s .maxInsertIndex )
610589 end += minMatchLength - 1
611- startindex := s .index + 1
612- if startindex > s .maxInsertIndex {
613- startindex = s .maxInsertIndex
614- }
590+ startindex := min (s .index + 1 , s .maxInsertIndex )
615591 tocheck := d .window [startindex :end ]
616592 dstSize := len (tocheck ) - minMatchLength + 1
617593 if dstSize > 0 {
0 commit comments