Skip to content

Commit

Permalink
trie: small optimization of delete in fullNode case (ethereum#22979)
Browse files Browse the repository at this point in the history
When deleting in fullNode, and the new child node nn is not nil, there is no need
to check the number of non-nil entries in the node. This is because the fullNode 
must've contained at least two children before deletion, so there must be another
child node other than nn.

Co-authored-by: Felix Lange <fjl@twurst.com>
  • Loading branch information
2 people authored and atif-konasl committed Oct 15, 2021
1 parent 3b30d49 commit 80f8e62
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,14 @@ func (t *Trie) delete(n node, prefix, key []byte) (bool, node, error) {
n.flags = t.newFlag()
n.Children[key[0]] = nn

// Because n is a full node, it must've contained at least two children
// before the delete operation. If the new child value is non-nil, n still
// has at least two children after the deletion, and cannot be reduced to
// a short node.
if nn != nil {
return true, n, nil
}
// Reduction:
// Check how many non-nil entries are left after deleting and
// reduce the full node to a short node if only one entry is
// left. Since n must've contained at least two children
Expand Down

0 comments on commit 80f8e62

Please sign in to comment.