()
| 152 | } |
| 153 | |
| 154 | func (d *Decoder) UnpackBlock() []uint64 { |
| 155 | if len(d.uids) > 0 { |
| 156 | // We were previously preallocating the d.uids slice to block size. This caused slowdown |
| 157 | // because many blocks are small and only contain a few ints, causing wastage while still |
| 158 | // paying cost of allocation. |
| 159 | d.uids = d.uids[:0] |
| 160 | } |
| 161 | |
| 162 | if d.blockIdx >= len(d.Pack.Blocks) { |
| 163 | return d.uids |
| 164 | } |
| 165 | block := d.Pack.Blocks[d.blockIdx] |
| 166 | |
| 167 | last := block.Base |
| 168 | d.uids = append(d.uids, last) |
| 169 | |
| 170 | tmpUids := make([]uint32, 4) |
| 171 | var sum uint64 |
| 172 | encData := block.Deltas |
| 173 | |
| 174 | for uint32(len(d.uids)) < block.NumUids { |
| 175 | if len(encData) < 17 { |
| 176 | // Decode4 decodes 4 uids from encData. It moves slice(encData) forward while |
| 177 | // decoding and expects it to be of length >= 4 at all the stages. |
| 178 | // The SSE code tries to read 16 bytes past the header(1 byte). |
| 179 | // So we are padding encData to increase its length to 17 bytes. |
| 180 | // This is a workaround for https://github.com/dgryski/go-groupvarint/issues/1 |
| 181 | // |
| 182 | // We should NEVER write to encData, because it references block.Deltas, which is laid |
| 183 | // out on an allocator. |
| 184 | tmp := make([]byte, 17) |
| 185 | copy(tmp, encData) |
| 186 | encData = tmp |
| 187 | } |
| 188 | |
| 189 | groupvarint.Decode4(tmpUids, encData) |
| 190 | encData = encData[groupvarint.BytesUsed[encData[0]]:] |
| 191 | for i := range 4 { |
| 192 | sum = last + uint64(tmpUids[i]) |
| 193 | d.uids = append(d.uids, sum) |
| 194 | last = sum |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | d.uids = d.uids[:block.NumUids] |
| 199 | return d.uids |
| 200 | } |
| 201 | |
| 202 | // ApproxLen returns the approximate number of UIDs in the pb.UidPack object. |
| 203 | func (d *Decoder) ApproxLen() int { |
no test coverage detected