transaction: avoid reencoding and reading what can't be read
name old time/op new time/op delta DecodeFromBytes-8 1.79µs ± 2% 1.46µs ± 4% -18.44% (p=0.000 n=10+10) name old alloc/op new alloc/op delta DecodeFromBytes-8 800B ± 0% 624B ± 0% -22.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta DecodeFromBytes-8 10.0 ± 0% 8.0 ± 0% -20.00% (p=0.000 n=10+10)
This commit is contained in:
parent
d0620b24ec
commit
7808762ba0
4 changed files with 35 additions and 15 deletions
|
@ -31,6 +31,17 @@ func NewBinReaderFromBuf(b []byte) *BinReader {
|
|||
return NewBinReaderFromIO(r)
|
||||
}
|
||||
|
||||
// Len returns the number of bytes of the unread portion of the buffer if
|
||||
// reading from bytes.Reader or -1 otherwise.
|
||||
func (r *BinReader) Len() int {
|
||||
var res = -1
|
||||
byteReader, ok := r.r.(*bytes.Reader)
|
||||
if ok {
|
||||
res = byteReader.Len()
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// ReadU64LE reads a little-endian encoded uint64 value from the underlying
|
||||
// io.Reader. On read failures it returns zero.
|
||||
func (r *BinReader) ReadU64LE() uint64 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue