This file is indexed.

/usr/share/gocode/src/github.com/klauspost/compress/flate/snappy.go is in golang-github-klauspost-compress-dev 1.0-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
// Copyright 2011 The Snappy-Go Authors. All rights reserved.
// Modified for deflate by Klaus Post (c) 2015.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package flate

// We limit how far copy back-references can go, the same as the C++ code.
const maxOffset = 1 << 15

// emitLiteral writes a literal chunk and returns the number of bytes written.
func emitLiteral(dst *tokens, lit []byte) {
	ol := dst.n
	for i, v := range lit {
		dst.tokens[i+ol] = token(v)
	}
	dst.n += len(lit)
}

// emitCopy writes a copy chunk and returns the number of bytes written.
func emitCopy(dst *tokens, offset, length int) {
	dst.tokens[dst.n] = matchToken(uint32(length-3), uint32(offset-minOffsetSize))
	dst.n++
}

type snappyEnc interface {
	Encode(dst *tokens, src []byte)
	Reset()
}

func newSnappy(level int) snappyEnc {
	if useSSE42 {
		e := &snappySSE4{}
		switch level {
		case 3:
			e.enc = e.encodeL3
			return e
		}
	}
	e := &snappyGen{}
	switch level {
	case 1:
		e.enc = e.encodeL1
	case 2:
		e.enc = e.encodeL2
	case 3:
		e.enc = e.encodeL3
	default:
		panic("invalid level specified")
	}
	return e
}

const tableBits = 14             // Bits used in the table
const tableSize = 1 << tableBits // Size of the table

// snappyGen maintains the table for matches,
// and the previous byte block for level 2.
// This is the generic implementation.
type snappyGen struct {
	table [tableSize]int64
	block [maxStoreBlockSize]byte
	prev  []byte
	cur   int
	enc   func(dst *tokens, src []byte)
}

func (e *snappyGen) Encode(dst *tokens, src []byte) {
	e.enc(dst, src)
}

// EncodeL1 uses Snappy-like compression, but stores as Huffman
// blocks.
func (e *snappyGen) encodeL1(dst *tokens, src []byte) {
	// Return early if src is short.
	if len(src) <= 4 {
		if len(src) != 0 {
			emitLiteral(dst, src)
		}
		e.cur += 4
		return
	}

	// Ensure that e.cur doesn't wrap, mainly an issue on 32 bits.
	if e.cur > 1<<30 {
		e.cur = 0
	}

	// Iterate over the source bytes.
	var (
		s   int // The iterator position.
		t   int // The last position with the same hash as s.
		lit int // The start position of any pending literal bytes.
	)

	for s+3 < len(src) {
		// Update the hash table.
		b0, b1, b2, b3 := src[s], src[s+1], src[s+2], src[s+3]
		h := uint32(b0) | uint32(b1)<<8 | uint32(b2)<<16 | uint32(b3)<<24
		p := &e.table[(h*0x1e35a7bd)>>(32-tableBits)]
		// We need to to store values in [-1, inf) in table. To save
		// some initialization time, (re)use the table's zero value
		// and shift the values against this zero: add 1 on writes,
		// subtract 1 on reads.
		t, *p = int(*p)-1-e.cur, int64(s+1+e.cur)

		offset := uint(s - t - 1)

		// If t is invalid or src[s:s+4] differs from src[t:t+4], accumulate a literal byte.
		if t < 0 || offset >= (maxOffset-1) || b0 != src[t] || b1 != src[t+1] || b2 != src[t+2] || b3 != src[t+3] {
			// Skip 1 byte for 16 consecutive missed.
			s += 1 + ((s - lit) >> 4)
			continue
		}
		// Otherwise, we have a match. First, emit any pending literal bytes.
		if lit != s {
			emitLiteral(dst, src[lit:s])
		}
		// Extend the match to be as long as possible.
		s0 := s
		s1 := s + maxMatchLength
		if s1 > len(src) {
			s1 = len(src)
		}
		s, t = s+4, t+4
		for s < s1 && src[s] == src[t] {
			s++
			t++
		}
		// Emit the copied bytes.
		// inlined: emitCopy(dst, s-t, s-s0)

		dst.tokens[dst.n] = matchToken(uint32(s-s0-3), uint32(s-t-minOffsetSize))
		dst.n++
		lit = s
	}

	// Emit any final pending literal bytes and return.
	if lit != len(src) {
		emitLiteral(dst, src[lit:])
	}
	e.cur += len(src)
}

// EncodeL2 uses a similar algorithm to level 1, but is capable
// of matching across blocks giving better compression at a small slowdown.
func (e *snappyGen) encodeL2(dst *tokens, src []byte) {
	// Return early if src is short.
	if len(src) <= 4 {
		if len(src) != 0 {
			emitLiteral(dst, src)
		}
		e.prev = nil
		e.cur += len(src)
		return
	}

	// Ensure that e.cur doesn't wrap, mainly an issue on 32 bits.
	if e.cur > 1<<30 {
		e.cur = 0
	}

	// Iterate over the source bytes.
	var (
		s   int // The iterator position.
		t   int // The last position with the same hash as s.
		lit int // The start position of any pending literal bytes.
	)

	for s+3 < len(src) {
		// Update the hash table.
		b0, b1, b2, b3 := src[s], src[s+1], src[s+2], src[s+3]
		h := uint32(b0) | uint32(b1)<<8 | uint32(b2)<<16 | uint32(b3)<<24
		p := &e.table[(h*0x1e35a7bd)>>(32-tableBits)]
		// We need to to store values in [-1, inf) in table. To save
		// some initialization time, (re)use the table's zero value
		// and shift the values against this zero: add 1 on writes,
		// subtract 1 on reads.
		t, *p = int(*p)-1-e.cur, int64(s+1+e.cur)

		// If t is positive, the match starts in the current block
		if t >= 0 {

			offset := uint(s - t - 1)
			// Check that the offset is valid and that we match at least 4 bytes
			if offset >= (maxOffset-1) || b0 != src[t] || b1 != src[t+1] || b2 != src[t+2] || b3 != src[t+3] {
				// Skip 1 byte for 32 consecutive missed.
				s += 1 + ((s - lit) >> 5)
				continue
			}
			// Otherwise, we have a match. First, emit any pending literal bytes.
			if lit != s {
				emitLiteral(dst, src[lit:s])
			}
			// Extend the match to be as long as possible.
			s0 := s
			s1 := s + maxMatchLength
			if s1 > len(src) {
				s1 = len(src)
			}
			s, t = s+4, t+4
			for s < s1 && src[s] == src[t] {
				s++
				t++
			}
			// Emit the copied bytes.
			// inlined: emitCopy(dst, s-t, s-s0)
			dst.tokens[dst.n] = matchToken(uint32(s-s0-3), uint32(s-t-minOffsetSize))
			dst.n++
			lit = s
			continue
		}
		// We found a match in the previous block.
		tp := len(e.prev) + t
		if tp < 0 || t > -5 || s-t >= maxOffset || b0 != e.prev[tp] || b1 != e.prev[tp+1] || b2 != e.prev[tp+2] || b3 != e.prev[tp+3] {
			// Skip 1 byte for 32 consecutive missed.
			s += 1 + ((s - lit) >> 5)
			continue
		}
		// Otherwise, we have a match. First, emit any pending literal bytes.
		if lit != s {
			emitLiteral(dst, src[lit:s])
		}
		// Extend the match to be as long as possible.
		s0 := s
		s1 := s + maxMatchLength
		if s1 > len(src) {
			s1 = len(src)
		}
		s, tp = s+4, tp+4
		for s < s1 && src[s] == e.prev[tp] {
			s++
			tp++
			if tp == len(e.prev) {
				t = 0
				// continue in current buffer
				for s < s1 && src[s] == src[t] {
					s++
					t++
				}
				goto l
			}
		}
	l:
		// Emit the copied bytes.
		if t < 0 {
			t = tp - len(e.prev)
		}
		dst.tokens[dst.n] = matchToken(uint32(s-s0-3), uint32(s-t-minOffsetSize))
		dst.n++
		lit = s

	}

	// Emit any final pending literal bytes and return.
	if lit != len(src) {
		emitLiteral(dst, src[lit:])
	}
	e.cur += len(src)
	// Store this block, if it was full length.
	if len(src) == maxStoreBlockSize {
		copy(e.block[:], src)
		e.prev = e.block[:len(src)]
	} else {
		e.prev = nil
	}
}

// EncodeL3 uses a similar algorithm to level 2, but is capable
// will keep two matches per hash.
// Both hashes are checked if the first isn't ok, and the longest is selected.
func (e *snappyGen) encodeL3(dst *tokens, src []byte) {
	// Return early if src is short.
	if len(src) <= 4 {
		if len(src) != 0 {
			emitLiteral(dst, src)
		}
		e.prev = nil
		e.cur += len(src)
		return
	}

	// Ensure that e.cur doesn't wrap, mainly an issue on 32 bits.
	if e.cur > 1<<30 {
		e.cur = 0
	}

	// Iterate over the source bytes.
	var (
		s   int // The iterator position.
		lit int // The start position of any pending literal bytes.
	)

	for s+3 < len(src) {
		// Update the hash table.
		h := uint32(src[s]) | uint32(src[s+1])<<8 | uint32(src[s+2])<<16 | uint32(src[s+3])<<24
		p := &e.table[(h*0x1e35a7bd)>>(32-tableBits)]
		tmp := *p
		p1 := int(tmp & 0xffffffff) // Closest match position
		p2 := int(tmp >> 32)        // Furthest match position

		// We need to to store values in [-1, inf) in table. To save
		// some initialization time, (re)use the table's zero value
		// and shift the values against this zero: add 1 on writes,
		// subtract 1 on reads.
		t1 := p1 - 1 - e.cur

		var l2 int
		var t2 int
		l1 := e.matchlen(s, t1, src)
		// If fist match was ok, don't do the second.
		if l1 < 16 {
			t2 = p2 - 1 - e.cur
			l2 = e.matchlen(s, t2, src)

			// If both are short, continue
			if l1 < 4 && l2 < 4 {
				// Update hash table
				*p = int64(s+1+e.cur) | (int64(p1) << 32)
				// Skip 1 byte for 32 consecutive missed.
				s += 1 + ((s - lit) >> 5)
				continue
			}
		}

		// Otherwise, we have a match. First, emit any pending literal bytes.
		if lit != s {
			emitLiteral(dst, src[lit:s])
		}
		// Update hash table
		*p = int64(s+1+e.cur) | (int64(p1) << 32)

		// Store the longest match l1 will be closest, so we prefer that if equal length
		if l1 >= l2 {
			dst.tokens[dst.n] = matchToken(uint32(l1-3), uint32(s-t1-minOffsetSize))
			s += l1
		} else {
			dst.tokens[dst.n] = matchToken(uint32(l2-3), uint32(s-t2-minOffsetSize))
			s += l2
		}
		dst.n++
		lit = s
	}

	// Emit any final pending literal bytes and return.
	if lit != len(src) {
		emitLiteral(dst, src[lit:])
	}
	e.cur += len(src)
	// Store this block, if it was full length.
	if len(src) == maxStoreBlockSize {
		copy(e.block[:], src)
		e.prev = e.block[:len(src)]
	} else {
		e.prev = nil
	}
}

func (e *snappyGen) matchlen(s, t int, src []byte) int {
	// If t is invalid or src[s:s+4] differs from src[t:t+4], accumulate a literal byte.
	offset := uint(s - t - 1)

	// If we are inside the current block
	if t >= 0 {
		if offset >= (maxOffset-1) ||
			src[s] != src[t] || src[s+1] != src[t+1] ||
			src[s+2] != src[t+2] || src[s+3] != src[t+3] {
			return 0
		}
		// Extend the match to be as long as possible.
		s0 := s
		s1 := s + maxMatchLength
		if s1 > len(src) {
			s1 = len(src)
		}
		s, t = s+4, t+4
		for s < s1 && src[s] == src[t] {
			s++
			t++
		}
		return s - s0
	}

	// We found a match in the previous block.
	tp := len(e.prev) + t
	if tp < 0 || offset >= (maxOffset-1) || t > -5 ||
		src[s] != e.prev[tp] || src[s+1] != e.prev[tp+1] ||
		src[s+2] != e.prev[tp+2] || src[s+3] != e.prev[tp+3] {
		return 0
	}

	// Extend the match to be as long as possible.
	s0 := s
	s1 := s + maxMatchLength
	if s1 > len(src) {
		s1 = len(src)
	}
	s, tp = s+4, tp+4
	for s < s1 && src[s] == e.prev[tp] {
		s++
		tp++
		if tp == len(e.prev) {
			t = 0
			// continue in current buffer
			for s < s1 && src[s] == src[t] {
				s++
				t++
			}
			return s - s0
		}
	}
	return s - s0
}

// Reset the encoding table.
func (e *snappyGen) Reset() {
	e.prev = nil
}

// snappySSE4 extends snappyGen.
// This implementation can use SSE 4.2 for length matching.
type snappySSE4 struct {
	snappyGen
}

/*
// EncodeL1 uses Snappy-like compression, but stores as Huffman
// blocks.
func (e *snappySSE4) encodeL1(dst *tokens, src []byte) {
	// Return early if src is short.
	if len(src) <= 4 {
		if len(src) != 0 {
			emitLiteral(dst, src)
		}
		e.cur += 4
		return
	}

	// Ensure that e.cur doesn't wrap, mainly an issue on 32 bits.
	if e.cur > 1<<30 {
		e.cur = 0
	}

	// Iterate over the source bytes.
	var (
		s   int // The iterator position.
		t   int // The last position with the same hash as s.
		lit int // The start position of any pending literal bytes.
	)

	for s+3 < len(src) {
		// Update the hash table.
		h := uint32(src[s]) | uint32(src[s+1])<<8 | uint32(src[s+2])<<16 | uint32(src[s+3])<<24
		p := &e.table[(h*0x1e35a7bd)>>(32-tableBits)]
		// We need to to store values in [-1, inf) in table. To save
		// some initialization time, (re)use the table's zero value
		// and shift the values against this zero: add 1 on writes,
		// subtract 1 on reads.
		t, *p = int(*p)-1-e.cur, int64(s+1+e.cur)

		offset := uint(s - t - 1)

		// If t is invalid or src[s:s+4] differs from src[t:t+4], accumulate a literal byte.
		if t < 0 || offset >= (maxOffset-1) {
			// Skip 1 byte for 16 consecutive missed.
			s += 1 + ((s - lit) >> 4)
			continue
		}

		length := len(src) - s
		if length > maxMatchLength {
			length = maxMatchLength
		}
		// Extend the match to be as long as possible.
		match := matchLenSSE4(src[t:], src[s:], length)

		// Return if short.
		if match < 4 {
			s += 1 + (s-lit)>>4
			continue
		}

		// Otherwise, we have a match. First, emit any pending literal bytes.
		if lit != s {
			emitLiteral(dst, src[lit:s])
		}

		dst.tokens[dst.n] = matchToken(uint32(match-3), uint32(offset))
		dst.n++
		s += match
		lit = s
	}

	// Emit any final pending literal bytes and return.
	if lit != len(src) {
		emitLiteral(dst, src[lit:])
	}
	e.cur += len(src)
}

// EncodeL2 uses a similar algorithm to level 1, but is capable
// of matching across blocks giving better compression at a small slowdown.
func (e *snappySSE4) encodeL2(dst *tokens, src []byte) {
	// Return early if src is short.
	if len(src) <= 4 {
		if len(src) != 0 {
			emitLiteral(dst, src)
		}
		e.prev = nil
		e.cur += len(src)
		return
	}

	// Ensure that e.cur doesn't wrap, mainly an issue on 32 bits.
	if e.cur > 1<<30 {
		e.cur = 0
	}

	// Iterate over the source bytes.
	var (
		s   int // The iterator position.
		t   int // The last position with the same hash as s.
		lit int // The start position of any pending literal bytes.
	)

	for s+3 < len(src) {
		// Update the hash table.
		b0, b1, b2, b3 := src[s], src[s+1], src[s+2], src[s+3]
		h := uint32(b0) | uint32(b1)<<8 | uint32(b2)<<16 | uint32(b3)<<24
		p := &e.table[(h*0x1e35a7bd)>>(32-tableBits)]
		// We need to to store values in [-1, inf) in table. To save
		// some initialization time, (re)use the table's zero value
		// and shift the values against this zero: add 1 on writes,
		// subtract 1 on reads.
		t, *p = int(*p)-1-e.cur, int64(s+1+e.cur)

		// If t is positive, the match starts in the current block
		if t >= 0 {
			offset := uint(s - t - 1)

			// If t is invalid or src[s:s+4] differs from src[t:t+4], accumulate a literal byte.
			if t < 0 || offset >= (maxOffset-1) {
				// Skip 1 byte for 16 consecutive missed.
				s += 1 + ((s - lit) >> 5)
				continue
			}

			length := maxMatchLength
			if length > len(src)-s {
				length = len(src) - s
			}
			// Extend the match to be as long as possible.
			match := matchLenSSE4(src[t:], src[s:], length)

			// Return if short.
			if match < 4 {
				s += 1 + (s-lit)>>5
				continue
			}

			// Otherwise, we have a match. First, emit any pending literal bytes.
			if lit != s {
				emitLiteral(dst, src[lit:s])
			}

			dst.tokens[dst.n] = matchToken(uint32(match-3), uint32(offset))
			s += match
			dst.n++
			lit = s
			continue
		}

		// We found a match in the previous block.
		tp := len(e.prev) + t
		if tp < 0 || t > -5 || s-t >= maxOffset || b0 != e.prev[tp] || b1 != e.prev[tp+1] || b2 != e.prev[tp+2] || b3 != e.prev[tp+3] {
			// Skip 1 byte for 32 consecutive missed.
			s += 1 + ((s - lit) >> 5)
			continue
		}
		// Otherwise, we have a match. First, emit any pending literal bytes.
		if lit != s {
			emitLiteral(dst, src[lit:s])
		}
		// Extend the match to be as long as possible.
		s0 := s
		s1 := s + maxMatchLength
		if s1 > len(src) {
			s1 = len(src)
		}
		s, tp = s+4, tp+4
		for s < s1 && src[s] == e.prev[tp] {
			s++
			tp++
			if tp == len(e.prev) {
				t = 0
				// continue in current buffer
				for s < s1 && src[s] == src[t] {
					s++
					t++
				}
				goto l
			}
		}
	l:
		// Emit the copied bytes.
		// inlined: emitCopy(dst, s-t, s-s0)
		if t < 0 {
			t = tp - len(e.prev)
		}
		dst.tokens[dst.n] = matchToken(uint32(s-s0-3), uint32(s-t-minOffsetSize))
		dst.n++
		lit = s
		continue

	}

	// Emit any final pending literal bytes and return.
	if lit != len(src) {
		emitLiteral(dst, src[lit:])
	}
	e.cur += len(src)
	// Store this block, if it was full length.
	if len(src) == maxStoreBlockSize {
		copy(e.block[:], src)
		e.prev = e.block[:len(src)]
	} else {
		e.prev = nil
	}
}
*/

// EncodeL3 uses a similar algorithm to level 2,
// but will keep two matches per hash.
// Both hashes are checked if the first isn't ok, and the longest is selected.
func (e *snappySSE4) encodeL3(dst *tokens, src []byte) {
	// Return early if src is short.
	if len(src) <= 4 {
		if len(src) != 0 {
			emitLiteral(dst, src)
		}
		e.prev = nil
		e.cur += len(src)
		return
	}

	// Ensure that e.cur doesn't wrap, mainly an issue on 32 bits.
	if e.cur > 1<<30 {
		e.cur = 0
	}

	// Iterate over the source bytes.
	var (
		s   int // The iterator position.
		lit int // The start position of any pending literal bytes.
	)

	for s+3 < len(src) {
		// Load potential matches from hash table.
		h := uint32(src[s]) | uint32(src[s+1])<<8 | uint32(src[s+2])<<16 | uint32(src[s+3])<<24
		p := &e.table[(h*0x1e35a7bd)>>(32-tableBits)]
		tmp := *p
		p1 := int(tmp & 0xffffffff) // Closest match position
		p2 := int(tmp >> 32)        // Furthest match position

		// We need to to store values in [-1, inf) in table. To save
		// some initialization time, (re)use the table's zero value
		// and shift the values against this zero: add 1 on writes,
		// subtract 1 on reads.
		t1 := int(p1) - 1 - e.cur

		var l2 int
		var t2 int
		l1 := e.matchlen(s, t1, src)
		// If fist match was ok, don't do the second.
		if l1 < 16 {
			t2 = int(p2) - 1 - e.cur
			l2 = e.matchlen(s, t2, src)

			// If both are short, continue
			if l1 < 4 && l2 < 4 {
				// Update hash table
				*p = int64(s+1+e.cur) | (int64(p1) << 32)
				// Skip 1 byte for 32 consecutive missed.
				s += 1 + ((s - lit) >> 5)
				continue
			}
		}

		// Otherwise, we have a match. First, emit any pending literal bytes.
		if lit != s {
			emitLiteral(dst, src[lit:s])
		}
		// Update hash table
		*p = int64(s+1+e.cur) | (int64(p1) << 32)

		// Store the longest match l1 will be closest, so we prefer that if equal length
		if l1 >= l2 {
			dst.tokens[dst.n] = matchToken(uint32(l1-3), uint32(s-t1-minOffsetSize))
			s += l1
		} else {
			dst.tokens[dst.n] = matchToken(uint32(l2-3), uint32(s-t2-minOffsetSize))
			s += l2
		}
		dst.n++
		lit = s
	}

	// Emit any final pending literal bytes and return.
	if lit != len(src) {
		emitLiteral(dst, src[lit:])
	}
	e.cur += len(src)
	// Store this block, if it was full length.
	if len(src) == maxStoreBlockSize {
		copy(e.block[:], src)
		e.prev = e.block[:len(src)]
	} else {
		e.prev = nil
	}
}

func (e *snappySSE4) matchlen(s, t int, src []byte) int {
	// If t is invalid or src[s:s+4] differs from src[t:t+4], accumulate a literal byte.
	offset := uint(s - t - 1)

	// If we are inside the current block
	if t >= 0 {
		if offset >= (maxOffset - 1) {
			return 0
		}
		length := len(src) - s
		if length > maxMatchLength {
			length = maxMatchLength
		}
		// Extend the match to be as long as possible.
		return matchLenSSE4(src[t:], src[s:], length)
	}

	// We found a match in the previous block.
	tp := len(e.prev) + t
	if tp < 0 || offset >= (maxOffset-1) || t > -5 ||
		src[s] != e.prev[tp] || src[s+1] != e.prev[tp+1] ||
		src[s+2] != e.prev[tp+2] || src[s+3] != e.prev[tp+3] {
		return 0
	}

	// Extend the match to be as long as possible.
	s0 := s
	s1 := s + maxMatchLength
	if s1 > len(src) {
		s1 = len(src)
	}
	s, tp = s+4, tp+4
	for s < s1 && src[s] == e.prev[tp] {
		s++
		tp++
		if tp == len(e.prev) {
			t = 0
			// continue in current buffer
			for s < s1 && src[s] == src[t] {
				s++
				t++
			}
			return s - s0
		}
	}
	return s - s0
}