trie: make stacktrie use less alloc:y encoders
This commit is contained in:
parent
c7f6aec7db
commit
5b6a6e4986
|
@ -318,19 +318,13 @@ func (t *StackTrie) hash(st *stNode, path []byte) {
|
||||||
return
|
return
|
||||||
|
|
||||||
case branchNode:
|
case branchNode:
|
||||||
var nodes fullNode
|
var nodes fullnodeEncoder
|
||||||
for i, child := range st.children {
|
for i, child := range st.children {
|
||||||
if child == nil {
|
if child == nil {
|
||||||
nodes.Children[i] = nilValueNode
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
t.hash(child, append(path, byte(i)))
|
t.hash(child, append(path, byte(i)))
|
||||||
|
nodes.Children[i] = child.val
|
||||||
if len(child.val) < 32 {
|
|
||||||
nodes.Children[i] = rawNode(child.val)
|
|
||||||
} else {
|
|
||||||
nodes.Children[i] = hashNode(child.val)
|
|
||||||
}
|
|
||||||
st.children[i] = nil
|
st.children[i] = nil
|
||||||
stPool.Put(child.reset()) // Release child back to pool.
|
stPool.Put(child.reset()) // Release child back to pool.
|
||||||
}
|
}
|
||||||
|
@ -342,11 +336,9 @@ func (t *StackTrie) hash(st *stNode, path []byte) {
|
||||||
t.hash(st.children[0], append(path, st.key...))
|
t.hash(st.children[0], append(path, st.key...))
|
||||||
|
|
||||||
// encode the extension node
|
// encode the extension node
|
||||||
n := shortNode{Key: hexToCompactInPlace(st.key)}
|
n := shortNodeEncoder{
|
||||||
if len(st.children[0].val) < 32 {
|
Key: hexToCompactInPlace(st.key),
|
||||||
n.Val = rawNode(st.children[0].val)
|
Val: st.children[0].val,
|
||||||
} else {
|
|
||||||
n.Val = hashNode(st.children[0].val)
|
|
||||||
}
|
}
|
||||||
n.encode(t.h.encbuf)
|
n.encode(t.h.encbuf)
|
||||||
blob = t.h.encodedBytes()
|
blob = t.h.encodedBytes()
|
||||||
|
@ -356,9 +348,13 @@ func (t *StackTrie) hash(st *stNode, path []byte) {
|
||||||
|
|
||||||
case leafNode:
|
case leafNode:
|
||||||
st.key = append(st.key, byte(16))
|
st.key = append(st.key, byte(16))
|
||||||
n := shortNode{Key: hexToCompactInPlace(st.key), Val: valueNode(st.val)}
|
{
|
||||||
|
w := t.h.encbuf
|
||||||
n.encode(t.h.encbuf)
|
offset := w.List()
|
||||||
|
w.WriteBytes(hexToCompactInPlace(st.key))
|
||||||
|
w.WriteBytes(st.val)
|
||||||
|
w.ListEnd(offset)
|
||||||
|
}
|
||||||
blob = t.h.encodedBytes()
|
blob = t.h.encodedBytes()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue