tryWriteCopy tries to copy a string at a given (distance, length) to the output. This specialized version is optimized for short distances. This method is designed to be inlined for performance reasons. This invariant must be kept: 0 < dist <= histSize()
(dist, length int)
| 149 | // |
| 150 | // This invariant must be kept: 0 < dist <= histSize() |
| 151 | func (dd *dictDecoder) tryWriteCopy(dist, length int) int { |
| 152 | dstPos := dd.wrPos |
| 153 | endPos := dstPos + length |
| 154 | if dstPos < dist || endPos > len(dd.hist) { |
| 155 | return 0 |
| 156 | } |
| 157 | dstBase := dstPos |
| 158 | srcPos := dstPos - dist |
| 159 | |
| 160 | // Copy possibly overlapping section before destination position. |
| 161 | loop: |
| 162 | dstPos += copy(dd.hist[dstPos:endPos], dd.hist[srcPos:dstPos]) |
| 163 | if dstPos < endPos { |
| 164 | goto loop // Avoid for-loop so that this function can be inlined |
| 165 | } |
| 166 | |
| 167 | dd.wrPos = dstPos |
| 168 | return dstPos - dstBase |
| 169 | } |
| 170 | |
| 171 | // appendWindow appends the current sliding window (up to len(hist) most recent |
| 172 | // bytes, oldest first) to dst. |
no outgoing calls