mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
trie/hasher: skip rlp encoding when not needed
This commit is contained in:
parent
2a9d1e7067
commit
40789748f7
1 changed files with 10 additions and 10 deletions
|
|
@ -165,6 +165,9 @@ func (h *hasher) store(n node, db *Database, force bool) (node, error) {
|
||||||
if _, isHash := n.(hashNode); n == nil || isHash {
|
if _, isHash := n.(hashNode); n == nil || isHash {
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
// We might already have the hash
|
||||||
|
hash, _ := n.cache()
|
||||||
|
if hash == nil {
|
||||||
// Generate the RLP encoding of the node
|
// Generate the RLP encoding of the node
|
||||||
h.tmp.Reset()
|
h.tmp.Reset()
|
||||||
if err := rlp.Encode(&h.tmp, n); err != nil {
|
if err := rlp.Encode(&h.tmp, n); err != nil {
|
||||||
|
|
@ -174,11 +177,8 @@ func (h *hasher) store(n node, db *Database, force bool) (node, error) {
|
||||||
return n, nil // Nodes smaller than 32 bytes are stored inside their parent
|
return n, nil // Nodes smaller than 32 bytes are stored inside their parent
|
||||||
}
|
}
|
||||||
// Larger nodes are replaced by their hash and stored in the database.
|
// Larger nodes are replaced by their hash and stored in the database.
|
||||||
hash, _ := n.cache()
|
|
||||||
if hash == nil {
|
|
||||||
hash = h.makeHashNode(h.tmp)
|
hash = h.makeHashNode(h.tmp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if db != nil {
|
if db != nil {
|
||||||
// We are pooling the trie nodes into an intermediate memory cache
|
// We are pooling the trie nodes into an intermediate memory cache
|
||||||
hash := common.BytesToHash(hash)
|
hash := common.BytesToHash(hash)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue