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

Method Encode

zstd/enc_fast.go:534–790  ·  view source on GitHub ↗

Encode will encode the content, with a dictionary if initialized for it.

(blk *blockEnc, src []byte)

Source from the content-addressed store, hash-verified

532
533// Encode will encode the content, with a dictionary if initialized for it.
534func (e *fastEncoderDict) Encode(blk *blockEnc, src []byte) {
535 const (
536 inputMargin = 8
537 minNonLiteralBlockSize = 1 + 1 + inputMargin
538 )
539 if e.allDirty || len(src) > 32<<10 {
540 e.fastEncoder.Encode(blk, src)
541 e.allDirty = true
542 return
543 }
544 // Protect against e.cur wraparound.
545 for e.cur >= e.bufferReset-int32(len(e.hist)) {
546 if len(e.hist) == 0 {
547 e.table = [tableSize]tableEntry{}
548 e.cur = e.maxMatchOff
549 break
550 }
551 // Shift down everything in the table that isn't already too far away.
552 minOff := e.cur + int32(len(e.hist)) - e.maxMatchOff
553 for i := range e.table[:] {
554 v := e.table[i].offset
555 if v < minOff {
556 v = 0
557 } else {
558 v = v - e.cur + e.maxMatchOff
559 }
560 e.table[i].offset = v
561 }
562 e.cur = e.maxMatchOff
563 break
564 }
565
566 s := e.addBlock(src)
567 blk.size = len(src)
568 if len(src) < minNonLiteralBlockSize {
569 blk.extraLits = len(src)
570 blk.literals = blk.literals[:len(src)]
571 copy(blk.literals, src)
572 return
573 }
574
575 // Override src
576 src = e.hist
577 sLimit := int32(len(src)) - inputMargin
578 // stepSize is the number of bytes to skip on every main loop iteration.
579 // It should be >= 2.
580 const stepSize = 2
581
582 // TEMPLATE
583 const hashLog = tableBits
584 // seems global, but would be nice to tweak.
585 const kSearchStrength = 7
586
587 // nextEmit is where in src the next emitLiteral should start from.
588 nextEmit := s
589 cv := load6432(src, s)
590
591 // Relative offsets

Callers

nothing calls this directly

Calls 8

markShardDirtyMethod · 0.95
printlnFunction · 0.85
load6432Function · 0.70
hashLenFunction · 0.70
load3232Function · 0.70
EncodeMethod · 0.65
addBlockMethod · 0.45
matchlenMethod · 0.45

Tested by

no test coverage detected