mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 13:21:37 +00:00
trie: cleanup
This commit is contained in:
parent
8e8031c107
commit
dcf67c04a4
1 changed files with 6 additions and 8 deletions
|
|
@ -87,9 +87,7 @@ func (c *committer) commit(path []byte, n node, parallel bool) node {
|
||||||
|
|
||||||
// commitChildren commits the children of the given fullnode
|
// commitChildren commits the children of the given fullnode
|
||||||
func (c *committer) commitChildren(path []byte, n *fullNode, parallel bool) {
|
func (c *committer) commitChildren(path []byte, n *fullNode, parallel bool) {
|
||||||
var (
|
childIndices := make([]int, 0, 16)
|
||||||
index = make([]int, 0, 16)
|
|
||||||
)
|
|
||||||
for i := 0; i < 16; i++ {
|
for i := 0; i < 16; i++ {
|
||||||
child := n.Children[i]
|
child := n.Children[i]
|
||||||
if child == nil {
|
if child == nil {
|
||||||
|
|
@ -101,13 +99,13 @@ func (c *committer) commitChildren(path []byte, n *fullNode, parallel bool) {
|
||||||
if _, ok := child.(hashNode); ok {
|
if _, ok := child.(hashNode); ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
index = append(index, i)
|
childIndices = append(childIndices, i)
|
||||||
}
|
}
|
||||||
if !parallel {
|
if !parallel {
|
||||||
// Commit the child recursively and store the "hashed" value.
|
// Commit the child recursively and store the "hashed" value.
|
||||||
// Note the returned node can be some embedded nodes, so it's
|
// Note the returned node can be some embedded nodes, so it's
|
||||||
// possible the type is not hashNode.
|
// possible the type is not hashNode.
|
||||||
for _, i := range index {
|
for _, i := range childIndices {
|
||||||
n.Children[i] = c.commit(append(path, byte(i)), n.Children[i], false)
|
n.Children[i] = c.commit(append(path, byte(i)), n.Children[i], false)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -115,15 +113,15 @@ func (c *committer) commitChildren(path []byte, n *fullNode, parallel bool) {
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
nodesMu sync.Mutex
|
nodesMu sync.Mutex
|
||||||
)
|
)
|
||||||
wg.Add(len(index))
|
wg.Add(len(childIndices))
|
||||||
for _, i := range index {
|
for _, i := range childIndices {
|
||||||
go func(index int) {
|
go func(index int) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
p := append(path, byte(index))
|
p := append(path, byte(index))
|
||||||
childSet := trienode.NewNodeSet(c.nodes.Owner)
|
childSet := trienode.NewNodeSet(c.nodes.Owner)
|
||||||
childCommitter := newCommitter(childSet, c.tracer, c.collectLeaf)
|
childCommitter := newCommitter(childSet, c.tracer, c.collectLeaf)
|
||||||
n.Children[index] = childCommitter.commit(p, n.Children[i], false)
|
n.Children[index] = childCommitter.commit(p, n.Children[index], false)
|
||||||
|
|
||||||
nodesMu.Lock()
|
nodesMu.Lock()
|
||||||
c.nodes.MergeDisjoint(childSet)
|
c.nodes.MergeDisjoint(childSet)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue