MCPcopy
hub / github.com/klauspost/compress / tryWriteCopy

Method tryWriteCopy

flate/dict_decoder.go:151–169  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

149//
150// This invariant must be kept: 0 < dist <= histSize()
151func (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.
161loop:
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.

Callers 6

TestDictDecoderFunction · 0.95
huffmanBytesBufferMethod · 0.80
huffmanBytesReaderMethod · 0.80
huffmanBufioReaderMethod · 0.80
huffmanStringsReaderMethod · 0.80
huffmanGenericReaderMethod · 0.80

Calls

no outgoing calls

Tested by 1

TestDictDecoderFunction · 0.76