read2buf reads exactly n bytes from the reader dec.in into the buffer dec.buf to reduce memory allocs. The buffer grows automatically.
(n int)
| 87 | // to reduce memory allocs. |
| 88 | // The buffer grows automatically. |
| 89 | func (dec *decoder) read2buf(n int) { |
| 90 | if cap(dec.buf) < n { |
| 91 | dec.buf = make([]byte, n) |
| 92 | } else { |
| 93 | dec.buf = dec.buf[:n] |
| 94 | } |
| 95 | if _, err := io.ReadFull(dec.in, dec.buf); err != nil { |
| 96 | panic(err) |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | // decodeU decodes uint32 obtained from the reader dec.in. |
| 101 | // The goal is to reduce memory allocs. |