Encode mimmics functionality in zstd_fast.c
(blk *blockEnc, src []byte)
| 37 | |
| 38 | // Encode mimmics functionality in zstd_fast.c |
| 39 | func (e *fastEncoder) Encode(blk *blockEnc, src []byte) { |
| 40 | const ( |
| 41 | inputMargin = 8 |
| 42 | minNonLiteralBlockSize = 1 + 1 + inputMargin |
| 43 | ) |
| 44 | |
| 45 | // Protect against e.cur wraparound. |
| 46 | for e.cur >= e.bufferReset-int32(len(e.hist)) { |
| 47 | if len(e.hist) == 0 { |
| 48 | for i := range e.table[:] { |
| 49 | e.table[i] = tableEntry{} |
| 50 | } |
| 51 | e.cur = e.maxMatchOff |
| 52 | break |
| 53 | } |
| 54 | // Shift down everything in the table that isn't already too far away. |
| 55 | minOff := e.cur + int32(len(e.hist)) - e.maxMatchOff |
| 56 | for i := range e.table[:] { |
| 57 | v := e.table[i].offset |
| 58 | if v < minOff { |
| 59 | v = 0 |
| 60 | } else { |
| 61 | v = v - e.cur + e.maxMatchOff |
| 62 | } |
| 63 | e.table[i].offset = v |
| 64 | } |
| 65 | e.cur = e.maxMatchOff |
| 66 | break |
| 67 | } |
| 68 | |
| 69 | s := e.addBlock(src) |
| 70 | blk.size = len(src) |
| 71 | if len(src) < minNonLiteralBlockSize { |
| 72 | blk.extraLits = len(src) |
| 73 | blk.literals = blk.literals[:len(src)] |
| 74 | copy(blk.literals, src) |
| 75 | return |
| 76 | } |
| 77 | |
| 78 | // Override src |
| 79 | src = e.hist |
| 80 | sLimit := int32(len(src)) - inputMargin |
| 81 | // stepSize is the number of bytes to skip on every main loop iteration. |
| 82 | // It should be >= 2. |
| 83 | const stepSize = 2 |
| 84 | |
| 85 | // TEMPLATE |
| 86 | const hashLog = tableBits |
| 87 | // seems global, but would be nice to tweak. |
| 88 | const kSearchStrength = 6 |
| 89 | |
| 90 | // nextEmit is where in src the next emitLiteral should start from. |
| 91 | nextEmit := s |
| 92 | cv := load6432(src, s) |
| 93 | |
| 94 | // Relative offsets |
| 95 | offset1 := int32(blk.recentOffsets[0]) |
| 96 | offset2 := int32(blk.recentOffsets[1]) |