crypto/merkle: pre-allocate data slice in innherHash (#6443)

So we can reduce pressure on runtime for checking that slice has enough
capacity before appending.
This commit is contained in:
Cuong Manh Le
2021-05-12 11:02:15 +02:00
committed by GitHub
parent fdd506a126
commit a9fc0c32b2
2 changed files with 6 additions and 1 deletions
+5 -1
View File
@@ -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)
}