Skip to content

Commit 87d48c2

Browse files
Cuong Manh LeJayT106
authored andcommitted
crypto/merkle: pre-allocate data slice in innherHash (tendermint#6443)
So we can reduce pressure on runtime for checking that slice has enough capacity before appending.
1 parent 21a3bbd commit 87d48c2

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

crypto/merkle/hash.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@ func leafHash(leaf []byte) []byte {
2222

2323
// returns tmhash(0x01 || left || right)
2424
func innerHash(left []byte, right []byte) []byte {
25-
return tmhash.Sum(append(innerPrefix, append(left, right...)...))
25+
data := make([]byte, len(innerPrefix)+len(left)+len(right))
26+
n := copy(data, innerPrefix)
27+
n += copy(data[n:], left)
28+
copy(data[n:], right)
29+
return tmhash.Sum(data)
2630
}

0 commit comments

Comments
 (0)