EncodeL1 uses a similar algorithm to level 1
(dst *tokens, src []byte)
| 16 | |
| 17 | // EncodeL1 uses a similar algorithm to level 1 |
| 18 | func (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 |
nothing calls this directly
no test coverage detected