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(). // writes via Bytes().
type BufBinWriter struct { type BufBinWriter struct {
*BinWriter *BinWriter
buf *bytes.Buffer buf bytes.Buffer
} }
// NewBufBinWriter makes a BufBinWriter with an empty byte buffer. // NewBufBinWriter makes a BufBinWriter with an empty byte buffer.
func NewBufBinWriter() *BufBinWriter { func NewBufBinWriter() *BufBinWriter {
b := new(bytes.Buffer) b := new(BufBinWriter)
return &BufBinWriter{BinWriter: NewBinWriterFromIO(b), buf: b} b.BinWriter = NewBinWriterFromIO(&b.buf)
return b
} }
// Len returns the number of bytes of the unread portion of the buffer. // Len returns the number of bytes of the unread portion of the buffer.