Skip to content

Commit 4b4dd6d

Browse files
committed
Move buffer declaration outside loops. Use buffer.Reset() inside loops.
1 parent 74000cc commit 4b4dd6d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

types/block.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,16 @@ func (b Block) ID() BlockID {
111111
// transactions (one leaf per transaction).
112112
func (b Block) MerkleRoot() crypto.Hash {
113113
tree := crypto.NewTree()
114+
var buf bytes.Buffer
114115
for _, payout := range b.MinerPayouts {
115-
var b bytes.Buffer
116-
payout.MarshalSia(&b)
117-
tree.Push(b.Bytes())
116+
payout.MarshalSia(&buf)
117+
tree.Push(buf.Bytes())
118+
buf.Reset()
118119
}
119120
for _, txn := range b.Transactions {
120-
var b bytes.Buffer
121-
txn.MarshalSia(&b)
122-
tree.Push(b.Bytes())
121+
txn.MarshalSia(&buf)
122+
tree.Push(buf.Bytes())
123+
buf.Reset()
123124
}
124125
return tree.Root()
125126
}

0 commit comments

Comments
 (0)