You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is doable by calling thing.reader.Reset(r) however I also need to use (*reader).Peek but I can't specify the size.
So instead I write: thing.reader = *bufio.NewReaderWithSize(r, maximumBlockSize) which feels wrong.
Proposal:
// ResetWithSize is like [Reset] but it will allocate a new buffer if the current buffer is smaller than required.func (*Reader) ResetWithSize(r io.Reader, sizeint)
Potential implementation:
// ResetWithSize is like [Reset] but it will allocate a new buffer if the current buffer is smaller than required.func (b*Reader) ResetWithSize(r io.Reader, sizeint) {
iflen(b.buf) <size {
b.buf=make([]byte, size)
}
b.reset(r)
}
The text was updated successfully, but these errors were encountered:
It does seem strange that Reset allocates a new buffer but hard-codes defaultBufSize. 🤔
I wonder if it would be better to provide a more general Resize(size int) method, with the constraint that the new size must be less than or equal to the number of bytes already buffered (as reported by Buffered). It seems like that would work equally well for this use-case, and may address others as well.
I would like to embed the bufio as reader in my fields to avoid pointers to pointers, reduce allocations and memory used:
This is doable by calling
thing.reader.Reset(r)
however I also need to use(*reader).Peek
but I can't specify the size.So instead I write:
thing.reader = *bufio.NewReaderWithSize(r, maximumBlockSize)
which feels wrong.Proposal:
Potential implementation:
The text was updated successfully, but these errors were encountered: