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

Cherry-picking PR #6443

#### PR checklist

- [x] Tests written/updated, or no tests needed
- [x] `CHANGELOG_PENDING.md` updated, or no changelog entry needed
- [x] Updated relevant documentation (`docs/`) and code comments, or no
      documentation updates needed
This commit is contained in:
JayT106
2022-09-21 04:00:53 -04:00
committed by GitHub
parent e84d43ec93
commit bfdeccd649
2 changed files with 6 additions and 1 deletions

View File

@@ -22,6 +22,7 @@
### IMPROVEMENTS
- [pubsub] \#7319 Performance improvements for the event query API (@creachadair)
- [crypto/merkle] \#6443 Improve HashAlternatives performance (@cuonglm)
### BUG FIXES

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)
}