init should be used once the block has been created. If called more than once, the effect is the same as calling reset.
()
| 35 | // init should be used once the block has been created. |
| 36 | // If called more than once, the effect is the same as calling reset. |
| 37 | func (b *blockEnc) init() { |
| 38 | if b.lowMem { |
| 39 | // 1K literals |
| 40 | if cap(b.literals) < 1<<10 { |
| 41 | b.literals = make([]byte, 0, 1<<10) |
| 42 | } |
| 43 | const defSeqs = 20 |
| 44 | if cap(b.sequences) < defSeqs { |
| 45 | b.sequences = make([]seq, 0, defSeqs) |
| 46 | } |
| 47 | // 1K |
| 48 | if cap(b.output) < 1<<10 { |
| 49 | b.output = make([]byte, 0, 1<<10) |
| 50 | } |
| 51 | } else { |
| 52 | if cap(b.literals) < maxCompressedBlockSize { |
| 53 | b.literals = make([]byte, 0, maxCompressedBlockSize) |
| 54 | } |
| 55 | const defSeqs = 2000 |
| 56 | if cap(b.sequences) < defSeqs { |
| 57 | b.sequences = make([]seq, 0, defSeqs) |
| 58 | } |
| 59 | if cap(b.output) < maxCompressedBlockSize { |
| 60 | b.output = make([]byte, 0, maxCompressedBlockSize) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if b.coders.mlEnc == nil { |
| 65 | b.coders.mlEnc = &fseEncoder{} |
| 66 | b.coders.mlPrev = &fseEncoder{} |
| 67 | b.coders.ofEnc = &fseEncoder{} |
| 68 | b.coders.ofPrev = &fseEncoder{} |
| 69 | b.coders.llEnc = &fseEncoder{} |
| 70 | b.coders.llPrev = &fseEncoder{} |
| 71 | } |
| 72 | b.litEnc = &huff0.Scratch{WantLogLess: 4} |
| 73 | b.reset(nil) |
| 74 | } |
| 75 | |
| 76 | // initNewEncode can be used to reset offsets and encoders to the initial state. |
| 77 | func (b *blockEnc) initNewEncode() { |