mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 13:21:37 +00:00
trie/bintrie: use sha256.Sum256 with stack buffer in InternalNode.Hash
Replace the sync.Pool-based sha256 hashing with a single sha256.Sum256 call using a stack-allocated [64]byte buffer. This eliminates pool Get/Put overhead, two interface-dispatched Write() calls, the Sum(nil) heap allocation, and the BytesToHash conversion.
This commit is contained in:
parent
98b13f342f
commit
dfc7439cf5
1 changed files with 5 additions and 9 deletions
|
|
@ -17,6 +17,7 @@
|
|||
package bintrie
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
|
|
@ -124,19 +125,14 @@ func (bt *InternalNode) Hash() common.Hash {
|
|||
return bt.hash
|
||||
}
|
||||
|
||||
h := newSha256()
|
||||
defer returnSha256(h)
|
||||
var buf [64]byte
|
||||
if bt.left != nil {
|
||||
h.Write(bt.left.Hash().Bytes())
|
||||
} else {
|
||||
h.Write(zero[:])
|
||||
copy(buf[:32], bt.left.Hash().Bytes())
|
||||
}
|
||||
if bt.right != nil {
|
||||
h.Write(bt.right.Hash().Bytes())
|
||||
} else {
|
||||
h.Write(zero[:])
|
||||
copy(buf[32:], bt.right.Hash().Bytes())
|
||||
}
|
||||
bt.hash = common.BytesToHash(h.Sum(nil))
|
||||
bt.hash = sha256.Sum256(buf[:])
|
||||
bt.mustRecompute = false
|
||||
return bt.hash
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue