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
This commit is contained in:
Josh Rickmar 2014-06-23 21:39:04 -05:00
parent c54649be41
commit 9a3f83d493
2 changed files with 2 additions and 2 deletions

View file

@ -208,7 +208,7 @@ func NewBlock(msgBlock *btcwire.MsgBlock) *Block {
func NewBlockFromBytes(serializedBlock []byte) (*Block, error) { func NewBlockFromBytes(serializedBlock []byte) (*Block, error) {
// Deserialize the bytes into a MsgBlock. // Deserialize the bytes into a MsgBlock.
var msgBlock btcwire.MsgBlock var msgBlock btcwire.MsgBlock
br := bytes.NewBuffer(serializedBlock) br := bytes.NewReader(serializedBlock)
err := msgBlock.Deserialize(br) err := msgBlock.Deserialize(br)
if err != nil { if err != nil {
return nil, err return nil, err

2
tx.go
View file

@ -74,7 +74,7 @@ func NewTx(msgTx *btcwire.MsgTx) *Tx {
func NewTxFromBytes(serializedTx []byte) (*Tx, error) { func NewTxFromBytes(serializedTx []byte) (*Tx, error) {
// Deserialize the bytes into a MsgTx. // Deserialize the bytes into a MsgTx.
var msgTx btcwire.MsgTx var msgTx btcwire.MsgTx
br := bytes.NewBuffer(serializedTx) br := bytes.NewReader(serializedTx)
err := msgTx.Deserialize(br) err := msgTx.Deserialize(br)
if err != nil { if err != nil {
return nil, err return nil, err