io: drop one allocation from NewBufBinWriter

This commit is contained in:
Roman Khimov 2021-08-20 11:38:42 +03:00
parent a68a8aa8fc
commit 2e39f1a1e3

View file

@ -13,13 +13,14 @@ var ErrDrained = errors.New("buffer already drained")
// writes via Bytes().
type BufBinWriter struct {
*BinWriter
buf *bytes.Buffer
buf bytes.Buffer
}
// NewBufBinWriter makes a BufBinWriter with an empty byte buffer.
func NewBufBinWriter() *BufBinWriter {
b := new(bytes.Buffer)
return &BufBinWriter{BinWriter: NewBinWriterFromIO(b), buf: b}
b := new(BufBinWriter)
b.BinWriter = NewBinWriterFromIO(&b.buf)
return b
}
// Len returns the number of bytes of the unread portion of the buffer.