MCPcopy
hub / github.com/klauspost/compress / Encode

Method Encode

zstd/enc_better.go:579–1089  ·  view source on GitHub ↗

Encode improves compression...

(blk *blockEnc, src []byte)

Source from the content-addressed store, hash-verified

577
578// Encode improves compression...
579func (e *betterFastEncoderDict) Encode(blk *blockEnc, src []byte) {
580 const (
581 // Input margin is the number of bytes we read (8)
582 // and the maximum we will read ahead (2)
583 inputMargin = 8 + 2
584 minNonLiteralBlockSize = 16
585 )
586
587 // Protect against e.cur wraparound.
588 for e.cur >= e.bufferReset-int32(len(e.hist)) {
589 if len(e.hist) == 0 {
590 for i := range e.table[:] {
591 e.table[i] = tableEntry{}
592 }
593 for i := range e.longTable[:] {
594 e.longTable[i] = prevEntry{}
595 }
596 e.cur = e.maxMatchOff
597 e.allDirty = true
598 break
599 }
600 // Shift down everything in the table that isn't already too far away.
601 minOff := e.cur + int32(len(e.hist)) - e.maxMatchOff
602 for i := range e.table[:] {
603 v := e.table[i].offset
604 if v < minOff {
605 v = 0
606 } else {
607 v = v - e.cur + e.maxMatchOff
608 }
609 e.table[i].offset = v
610 }
611 for i := range e.longTable[:] {
612 v := e.longTable[i].offset
613 v2 := e.longTable[i].prev
614 if v < minOff {
615 v = 0
616 v2 = 0
617 } else {
618 v = v - e.cur + e.maxMatchOff
619 if v2 < minOff {
620 v2 = 0
621 } else {
622 v2 = v2 - e.cur + e.maxMatchOff
623 }
624 }
625 e.longTable[i] = prevEntry{
626 offset: v,
627 prev: v2,
628 }
629 }
630 e.allDirty = true
631 e.cur = e.maxMatchOff
632 break
633 }
634
635 s := e.addBlock(src)
636 blk.size = len(src)

Callers

nothing calls this directly

Calls 8

markLongShardDirtyMethod · 0.95
markShortShardDirtyMethod · 0.95
printlnFunction · 0.85
load6432Function · 0.70
hashLenFunction · 0.70
load3232Function · 0.70
addBlockMethod · 0.45
matchlenMethod · 0.45

Tested by

no test coverage detected