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

Method Encode

flate/level1.go:18–215  ·  view source on GitHub ↗

EncodeL1 uses a similar algorithm to level 1

(dst *tokens, src []byte)

Source from the content-addressed store, hash-verified

16
17// EncodeL1 uses a similar algorithm to level 1
18func (e *fastEncL1) Encode(dst *tokens, src []byte) {
19 const (
20 inputMargin = 12 - 1
21 minNonLiteralBlockSize = 1 + 1 + inputMargin
22 hashBytes = 5
23 )
24 if debugDeflate && e.cur < 0 {
25 panic(fmt.Sprint("e.cur < 0: ", e.cur))
26 }
27
28 // Protect against e.cur wraparound.
29 for e.cur >= bufferReset {
30 if len(e.hist) == 0 {
31 for i := range e.table[:] {
32 e.table[i] = tableEntry{}
33 }
34 e.cur = maxMatchOffset
35 break
36 }
37 // Shift down everything in the table that isn't already too far away.
38 minOff := e.cur + int32(len(e.hist)) - maxMatchOffset
39 for i := range e.table[:] {
40 v := e.table[i].offset
41 if v <= minOff {
42 v = 0
43 } else {
44 v = v - e.cur + maxMatchOffset
45 }
46 e.table[i].offset = v
47 }
48 e.cur = maxMatchOffset
49 }
50
51 s := e.addBlock(src)
52
53 // This check isn't in the Snappy implementation, but there, the caller
54 // instead of the callee handles this case.
55 if len(src) < minNonLiteralBlockSize {
56 // We do not fill the token table.
57 // This will be picked up by caller.
58 dst.n = uint16(len(src))
59 return
60 }
61
62 // Override src
63 src = e.hist
64 nextEmit := s
65
66 // sLimit is when to stop looking for offset/length copies. The inputMargin
67 // lets us use a fast path for emitLiteral in the main loop, while we are
68 // looking for copies.
69 sLimit := int32(len(src) - inputMargin)
70
71 // nextEmit is where in src the next emitLiteral should start from.
72 cv := load6432(src, s)
73
74 for {
75 const skipLog = 5

Callers

nothing calls this directly

Calls 10

Load8Function · 0.92
tokenTypeAlias · 0.85
offsetCodeFunction · 0.85
AddMatchLongMethod · 0.80
load6432Function · 0.70
hashLenFunction · 0.70
load3232Function · 0.70
emitLiteralFunction · 0.70
addBlockMethod · 0.45
matchlenLongMethod · 0.45

Tested by

no test coverage detected