grow ensures that the buffer has at least n free bytes of capacity. It grows the buffer to the next power of two if necessary.
(n int)
| 81 | // grow ensures that the buffer has at least n free bytes of capacity. |
| 82 | // It grows the buffer to the next power of two if necessary. |
| 83 | func (b *buffer) grow(n int) { |
| 84 | if req := len(*b) + n; req > cap(*b) { |
| 85 | p := math.Ceil(math.Log2(float64(req))) |
| 86 | *b = slices.Grow(*b, 1<<int(p)) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | // newBuffer creates a new buffer from the pool. |
| 91 | func newBuffer() *buffer { |