emitRepeat writes a repeat chunk and returns the number of bytes written. Length must be at least 4 and < 1<<24
(dst []byte, offset, length int)
| 116 | // emitRepeat writes a repeat chunk and returns the number of bytes written. |
| 117 | // Length must be at least 4 and < 1<<24 |
| 118 | func emitRepeat(dst []byte, offset, length int) int { |
| 119 | // Repeat offset, make length cheaper |
| 120 | length -= 4 |
| 121 | if length <= 4 { |
| 122 | dst[0] = uint8(length)<<2 | tagCopy1 |
| 123 | dst[1] = 0 |
| 124 | return 2 |
| 125 | } |
| 126 | if length < 8 && offset < 2048 { |
| 127 | // Encode WITH offset |
| 128 | dst[1] = uint8(offset) |
| 129 | dst[0] = uint8(offset>>8)<<5 | uint8(length)<<2 | tagCopy1 |
| 130 | return 2 |
| 131 | } |
| 132 | if length < (1<<8)+4 { |
| 133 | length -= 4 |
| 134 | dst[2] = uint8(length) |
| 135 | dst[1] = 0 |
| 136 | dst[0] = 5<<2 | tagCopy1 |
| 137 | return 3 |
| 138 | } |
| 139 | if length < (1<<16)+(1<<8) { |
| 140 | length -= 1 << 8 |
| 141 | dst[3] = uint8(length >> 8) |
| 142 | dst[2] = uint8(length >> 0) |
| 143 | dst[1] = 0 |
| 144 | dst[0] = 6<<2 | tagCopy1 |
| 145 | return 4 |
| 146 | } |
| 147 | const maxRepeat = (1 << 24) - 1 |
| 148 | length -= 1 << 16 |
| 149 | left := 0 |
| 150 | if length > maxRepeat { |
| 151 | left = length - maxRepeat + 4 |
| 152 | length = maxRepeat - 4 |
| 153 | } |
| 154 | dst[4] = uint8(length >> 16) |
| 155 | dst[3] = uint8(length >> 8) |
| 156 | dst[2] = uint8(length >> 0) |
| 157 | dst[1] = 0 |
| 158 | dst[0] = 7<<2 | tagCopy1 |
| 159 | if left > 0 { |
| 160 | return 5 + emitRepeat(dst[5:], offset, left) |
| 161 | } |
| 162 | return 5 |
| 163 | } |
| 164 | |
| 165 | // emitCopy writes a copy chunk and returns the number of bytes written. |
| 166 | // |
no outgoing calls
no test coverage detected
searching dependent graphs…