From 9a3f83d493646dfed633a3d19649ef7d6ab77322 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 23 Jun 2014 21:39:04 -0500 Subject: [PATCH] Switch bytes.Buffer to Reader where possible. bytes.Reader is a little bit more efficient than a bytes.Buffer when just reading, so in situations where only an io.Reader is needed (for Block and Tx deserialization), switch to a bytes.Reader. ok @davecgh --- block.go | 2 +- tx.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/block.go b/block.go index 13e10d5..0e5e514 100644 --- a/block.go +++ b/block.go @@ -208,7 +208,7 @@ func NewBlock(msgBlock *btcwire.MsgBlock) *Block { func NewBlockFromBytes(serializedBlock []byte) (*Block, error) { // Deserialize the bytes into a MsgBlock. var msgBlock btcwire.MsgBlock - br := bytes.NewBuffer(serializedBlock) + br := bytes.NewReader(serializedBlock) err := msgBlock.Deserialize(br) if err != nil { return nil, err diff --git a/tx.go b/tx.go index e3c1cc2..1660bf0 100644 --- a/tx.go +++ b/tx.go @@ -74,7 +74,7 @@ func NewTx(msgTx *btcwire.MsgTx) *Tx { func NewTxFromBytes(serializedTx []byte) (*Tx, error) { // Deserialize the bytes into a MsgTx. var msgTx btcwire.MsgTx - br := bytes.NewBuffer(serializedTx) + br := bytes.NewReader(serializedTx) err := msgTx.Deserialize(br) if err != nil { return nil, err