Skip to content

Commit

Permalink
trie: apply fastNodeEncoder to StackTrie
Browse files Browse the repository at this point in the history
  • Loading branch information
qianbin committed Jan 11, 2022
1 parent db9a648 commit 77a00b4
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions trie/stacktrie.go
Expand Up @@ -376,26 +376,26 @@ func (st *StackTrie) hash() {

switch st.nodeType {
case branchNode:
var nodes [17]node
var n rawFullNode
for i, child := range st.children {
if child == nil {
nodes[i] = nilValueNode
n[i] = nilValueNode
continue
}
child.hash()
if len(child.val) < 32 {
nodes[i] = rawNode(child.val)
n[i] = rawNode(child.val)
} else {
nodes[i] = hashNode(child.val)
n[i] = hashNode(child.val)
}
st.children[i] = nil // Reclaim mem from subtree
returnToPool(child)
}
nodes[16] = nilValueNode
n[16] = nilValueNode
h = newHasher(false)
defer returnHasherToPool(h)
h.tmp.Reset()
if err := rlp.Encode(&h.tmp, nodes); err != nil {
if err := frlp.Encode(&h.tmp, n); err != nil {
panic(err)
}
case extNode:
Expand All @@ -409,14 +409,11 @@ func (st *StackTrie) hash() {
} else {
valuenode = hashNode(st.children[0].val)
}
n := struct {
Key []byte
Val node
}{
n := &rawShortNode{
Key: hexToCompact(st.key),
Val: valuenode,
}
if err := rlp.Encode(&h.tmp, n); err != nil {
if err := frlp.Encode(&h.tmp, n); err != nil {
panic(err)
}
returnToPool(st.children[0])
Expand Down

0 comments on commit 77a00b4

Please sign in to comment.