mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 23:42:23 +00:00
io: don't allocate new error on every call to Bytes()
It makes no sense and we're using Bytes() pretty often.
This commit is contained in:
parent
894cfe29be
commit
b8dd284d3d
1 changed files with 4 additions and 1 deletions
|
@ -5,6 +5,9 @@ import (
|
|||
"errors"
|
||||
)
|
||||
|
||||
// ErrDrained is returned on an attempt to use already drained write buffer.
|
||||
var ErrDrained = errors.New("buffer already drained")
|
||||
|
||||
// BufBinWriter is an additional layer on top of BinWriter that
|
||||
// automatically creates buffer to write into that you can get after all
|
||||
// writes via Bytes().
|
||||
|
@ -29,7 +32,7 @@ func (bw *BufBinWriter) Bytes() []byte {
|
|||
if bw.Err != nil {
|
||||
return nil
|
||||
}
|
||||
bw.Err = errors.New("buffer already drained")
|
||||
bw.Err = ErrDrained
|
||||
return bw.buf.Bytes()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue