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

Method EncodeNoHist

zstd/enc_fast.go:294–531  ·  view source on GitHub ↗

EncodeNoHist will encode a block with no history and no following blocks. Most notable difference is that src will not be copied for history and we do not need to check for max match length.

(blk *blockEnc, src []byte)

Source from the content-addressed store, hash-verified

292// Most notable difference is that src will not be copied for history and
293// we do not need to check for max match length.
294func (e *fastEncoder) EncodeNoHist(blk *blockEnc, src []byte) {
295 const (
296 inputMargin = 8
297 minNonLiteralBlockSize = 1 + 1 + inputMargin
298 )
299 if debugEncoder {
300 if len(src) > maxCompressedBlockSize {
301 panic("src too big")
302 }
303 }
304
305 // Protect against e.cur wraparound.
306 if e.cur >= e.bufferReset {
307 for i := range e.table[:] {
308 e.table[i] = tableEntry{}
309 }
310 e.cur = e.maxMatchOff
311 }
312
313 s := int32(0)
314 blk.size = len(src)
315 if len(src) < minNonLiteralBlockSize {
316 blk.extraLits = len(src)
317 blk.literals = blk.literals[:len(src)]
318 copy(blk.literals, src)
319 return
320 }
321
322 sLimit := int32(len(src)) - inputMargin
323 // stepSize is the number of bytes to skip on every main loop iteration.
324 // It should be >= 2.
325 const stepSize = 2
326
327 // TEMPLATE
328 const hashLog = tableBits
329 // seems global, but would be nice to tweak.
330 const kSearchStrength = 6
331
332 // nextEmit is where in src the next emitLiteral should start from.
333 nextEmit := s
334 cv := load6432(src, s)
335
336 // Relative offsets
337 offset1 := int32(blk.recentOffsets[0])
338 offset2 := int32(blk.recentOffsets[1])
339
340 addLiterals := func(s *seq, until int32) {
341 if until == nextEmit {
342 return
343 }
344 blk.literals = append(blk.literals, src[nextEmit:until]...)
345 s.litLen = uint32(until - nextEmit)
346 }
347 if debugEncoder {
348 println("recent offsets:", blk.recentOffsets)
349 }
350
351encodeLoop:

Callers

nothing calls this directly

Calls 5

printlnFunction · 0.85
load6432Function · 0.70
hashLenFunction · 0.70
load3232Function · 0.70
matchlenMethod · 0.45

Tested by

no test coverage detected