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

Method Encode

flate/level6.go:11–325  ·  view source on GitHub ↗
(dst *tokens, src []byte)

Source from the content-addressed store, hash-verified

9}
10
11func (e *fastEncL6) Encode(dst *tokens, src []byte) {
12 const (
13 inputMargin = 12 - 1
14 minNonLiteralBlockSize = 1 + 1 + inputMargin
15 hashShortBytes = 4
16 )
17 if debugDeflate && e.cur < 0 {
18 panic(fmt.Sprint("e.cur < 0: ", e.cur))
19 }
20
21 // Protect against e.cur wraparound.
22 for e.cur >= bufferReset {
23 if len(e.hist) == 0 {
24 for i := range e.table[:] {
25 e.table[i] = tableEntry{}
26 }
27 for i := range e.bTable[:] {
28 e.bTable[i] = tableEntryPrev{}
29 }
30 e.cur = maxMatchOffset
31 break
32 }
33 // Shift down everything in the table that isn't already too far away.
34 minOff := e.cur + int32(len(e.hist)) - maxMatchOffset
35 for i := range e.table[:] {
36 v := e.table[i].offset
37 if v <= minOff {
38 v = 0
39 } else {
40 v = v - e.cur + maxMatchOffset
41 }
42 e.table[i].offset = v
43 }
44 for i := range e.bTable[:] {
45 v := e.bTable[i]
46 if v.Cur.offset <= minOff {
47 v.Cur.offset = 0
48 v.Prev.offset = 0
49 } else {
50 v.Cur.offset = v.Cur.offset - e.cur + maxMatchOffset
51 if v.Prev.offset <= minOff {
52 v.Prev.offset = 0
53 } else {
54 v.Prev.offset = v.Prev.offset - e.cur + maxMatchOffset
55 }
56 }
57 e.bTable[i] = v
58 }
59 e.cur = maxMatchOffset
60 }
61
62 s := e.addBlock(src)
63
64 // This check isn't in the Snappy implementation, but there, the caller
65 // instead of the callee handles this case.
66 if len(src) < minNonLiteralBlockSize {
67 // We do not fill the token table.
68 // This will be picked up by caller.

Callers

nothing calls this directly

Calls 10

tokenTypeAlias · 0.85
AddMatchLongMethod · 0.80
load6432Function · 0.70
hashLenFunction · 0.70
hash7Function · 0.70
load3232Function · 0.70
emitLiteralFunction · 0.70
addBlockMethod · 0.45
matchlenMethod · 0.45
matchlenLongMethod · 0.45

Tested by

no test coverage detected