Skip to content

Commit d0cb4b4

Browse files
Copilottzdybal
andcommitted
fix: optimize slice allocation to avoid reallocation
Co-authored-by: tzdybal <[email protected]>
1 parent 47f748c commit d0cb4b4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

consensus/propagation/types/types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,11 @@ func (c *CompactBlock) Proofs() ([]merkle.Proof, error) {
206206
return nil, errors.New("invalid number of partset hashes")
207207
}
208208

209-
c.proofsCache = make([]merkle.Proof, 0, len(c.PartsHashes))
209+
c.proofsCache = make([]merkle.Proof, len(c.PartsHashes))
210210

211211
root, proofs := merkle.ProofsFromLeafHashes(c.PartsHashes[:total])
212212
for i := range proofs {
213-
c.proofsCache = append(c.proofsCache, proofs[i])
213+
c.proofsCache[i] = proofs[i]
214214
}
215215

216216
if !bytes.Equal(root, c.Proposal.BlockID.PartSetHeader.Hash) {
@@ -219,7 +219,7 @@ func (c *CompactBlock) Proofs() ([]merkle.Proof, error) {
219219

220220
parityRoot, eproofs := merkle.ProofsFromLeafHashes(c.PartsHashes[total:])
221221
for i := range eproofs {
222-
c.proofsCache = append(c.proofsCache, eproofs[i])
222+
c.proofsCache[int(total)+i] = eproofs[i]
223223
}
224224

225225
if !bytes.Equal(c.BpHash, parityRoot) {

0 commit comments

Comments
 (0)