| 55 | } |
| 56 | |
| 57 | func (e *fastBase) addBlock(src []byte) int32 { |
| 58 | if debugAsserts && e.cur > e.bufferReset { |
| 59 | panic(fmt.Sprintf("ecur (%d) > buffer reset (%d)", e.cur, e.bufferReset)) |
| 60 | } |
| 61 | // check if we have space already |
| 62 | if len(e.hist)+len(src) > cap(e.hist) { |
| 63 | if cap(e.hist) == 0 { |
| 64 | e.ensureHist(len(src)) |
| 65 | } else { |
| 66 | if cap(e.hist) < int(e.maxMatchOff+maxCompressedBlockSize) { |
| 67 | panic(fmt.Errorf("unexpected buffer cap %d, want at least %d with window %d", cap(e.hist), e.maxMatchOff+maxCompressedBlockSize, e.maxMatchOff)) |
| 68 | } |
| 69 | // Move down |
| 70 | offset := int32(len(e.hist)) - e.maxMatchOff |
| 71 | copy(e.hist[0:e.maxMatchOff], e.hist[offset:]) |
| 72 | e.cur += offset |
| 73 | e.hist = e.hist[:e.maxMatchOff] |
| 74 | } |
| 75 | } |
| 76 | s := int32(len(e.hist)) |
| 77 | e.hist = append(e.hist, src...) |
| 78 | return s |
| 79 | } |
| 80 | |
| 81 | // ensureHist will ensure that history can keep at least this many bytes. |
| 82 | func (e *fastBase) ensureHist(n int) { |