Use bytes.NewReader for all deserialization.
Rather than using bytes.NewBuffer, which is a read/write entity (io.ReadWriter), use bytes.NewReader which is only a read entitiy (io.Reader). Benchmarking shows it's slightly faster and it's also technically more accurate since it ensures the data is read-only.
This commit is contained in:
parent
879a125a2f
commit
4e8e63e0d7
2 changed files with 4 additions and 4 deletions
2
chain.go
2
chain.go
|
@ -83,7 +83,7 @@ func (r FutureGetBlockResult) Receive() (*btcutil.Block, error) {
|
|||
|
||||
// Deserialize the block and return it.
|
||||
var msgBlock btcwire.MsgBlock
|
||||
msgBlock.Deserialize(bytes.NewBuffer(serializedBlock))
|
||||
msgBlock.Deserialize(bytes.NewReader(serializedBlock))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ func (r FutureGetRawTransactionResult) Receive() (*btcutil.Tx, error) {
|
|||
|
||||
// Deserialize the transaction and return it.
|
||||
var msgTx btcwire.MsgTx
|
||||
if err := msgTx.Deserialize(bytes.NewBuffer(serializedTx)); err != nil {
|
||||
if err := msgTx.Deserialize(bytes.NewReader(serializedTx)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return btcutil.NewTx(&msgTx), nil
|
||||
|
@ -240,7 +240,7 @@ func (r FutureCreateRawTransactionResult) Receive() (*btcwire.MsgTx, error) {
|
|||
|
||||
// Deserialize the transaction and return it.
|
||||
var msgTx btcwire.MsgTx
|
||||
if err := msgTx.Deserialize(bytes.NewBuffer(serializedTx)); err != nil {
|
||||
if err := msgTx.Deserialize(bytes.NewReader(serializedTx)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &msgTx, nil
|
||||
|
@ -357,7 +357,7 @@ func (r FutureSignRawTransactionResult) Receive() (*btcwire.MsgTx, bool, error)
|
|||
|
||||
// Deserialize the transaction and return it.
|
||||
var msgTx btcwire.MsgTx
|
||||
if err := msgTx.Deserialize(bytes.NewBuffer(serializedTx)); err != nil {
|
||||
if err := msgTx.Deserialize(bytes.NewReader(serializedTx)); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue