Browse Source

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.
pull/6454/head
Cuong Manh Le 4 years ago
committed by GitHub
parent
commit
a9fc0c32b2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +5
    -1
      crypto/merkle/hash.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -93,6 +93,7 @@ Friendly reminder: We have a [bug bounty program](https://hackerone.com/tendermi
- [rpc] \#6265 set cache control in http-rpc response header (@JayT106)
- [statesync] \#6378 Retry requests for snapshots and add a minimum discovery time (5s) for new snapshots.
- [node/state] \#6370 graceful shutdown in the consensus reactor (@JayT106)
- [crypto/merkle] \#6443 Improve HashAlternatives performance (@cuonglm)
### BUG FIXES


+ 5
- 1
crypto/merkle/hash.go 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)
}

Loading…
Cancel
Save