Skip to content

Commit

Permalink
crypto/merkle: pre-allocate data slice in innherHash (tendermint#6443)
Browse files Browse the repository at this point in the history
So we can reduce pressure on runtime for checking that slice has enough
capacity before appending.
  • Loading branch information
Cuong Manh Le authored and JayT106 committed Sep 16, 2022
1 parent 21a3bbd commit 87d48c2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crypto/merkle/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ func leafHash(leaf []byte) []byte {

// returns tmhash(0x01 || left || right)
func innerHash(left []byte, right []byte) []byte {
return tmhash.Sum(append(innerPrefix, append(left, right...)...))
data := make([]byte, len(innerPrefix)+len(left)+len(right))
n := copy(data, innerPrefix)
n += copy(data[n:], left)
copy(data[n:], right)
return tmhash.Sum(data)
}

0 comments on commit 87d48c2

Please sign in to comment.