readBinary cannot use mcache, because the memory allocated by readBinary will not be recycled.
(n int)
| 319 | |
| 320 | // readBinary cannot use mcache, because the memory allocated by readBinary will not be recycled. |
| 321 | func (b *UnsafeLinkBuffer) readBinary(n int) (p []byte) { |
| 322 | b.recalLen(-n) // re-cal length |
| 323 | |
| 324 | // single node |
| 325 | if b.isSingleNode(n) { |
| 326 | p = dirtmake.Bytes(n, n) |
| 327 | copy(p, b.read.Next(n)) |
| 328 | return p |
| 329 | } |
| 330 | p = dirtmake.Bytes(n, n) |
| 331 | // multiple nodes |
| 332 | var pIdx int |
| 333 | var l int |
| 334 | for ack := n; ack > 0; ack = ack - l { |
| 335 | l = b.read.Len() |
| 336 | if l >= ack { |
| 337 | pIdx += copy(p[pIdx:], b.read.Next(ack)) |
| 338 | break |
| 339 | } else if l > 0 { |
| 340 | pIdx += copy(p[pIdx:], b.read.Next(l)) |
| 341 | } |
| 342 | b.read = b.read.next |
| 343 | } |
| 344 | _ = pIdx |
| 345 | return p |
| 346 | } |
| 347 | |
| 348 | // ReadByte implements Reader. |
| 349 | func (b *UnsafeLinkBuffer) ReadByte() (p byte, err error) { |
no test coverage detected