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

Method addBlock

zstd/enc_base.go:57–79  ·  view source on GitHub ↗
(src []byte)

Source from the content-addressed store, hash-verified

55}
56
57func (e *fastBase) addBlock(src []byte) int32 {
58 if debugAsserts && e.cur > e.bufferReset {
59 panic(fmt.Sprintf("ecur (%d) > buffer reset (%d)", e.cur, e.bufferReset))
60 }
61 // check if we have space already
62 if len(e.hist)+len(src) > cap(e.hist) {
63 if cap(e.hist) == 0 {
64 e.ensureHist(len(src))
65 } else {
66 if cap(e.hist) < int(e.maxMatchOff+maxCompressedBlockSize) {
67 panic(fmt.Errorf("unexpected buffer cap %d, want at least %d with window %d", cap(e.hist), e.maxMatchOff+maxCompressedBlockSize, e.maxMatchOff))
68 }
69 // Move down
70 offset := int32(len(e.hist)) - e.maxMatchOff
71 copy(e.hist[0:e.maxMatchOff], e.hist[offset:])
72 e.cur += offset
73 e.hist = e.hist[:e.maxMatchOff]
74 }
75 }
76 s := int32(len(e.hist))
77 e.hist = append(e.hist, src...)
78 return s
79}
80
81// ensureHist will ensure that history can keep at least this many bytes.
82func (e *fastBase) ensureHist(n int) {

Callers 7

EncodeMethod · 0.45
EncodeMethod · 0.45
EncodeMethod · 0.45
EncodeMethod · 0.45
EncodeMethod · 0.45
EncodeMethod · 0.45
EncodeMethod · 0.45

Calls 1

ensureHistMethod · 0.95

Tested by

no test coverage detected