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
Evolution404 and fjl committed Jun 20, 2021
1 parent 7b6c836 commit 732a6a3
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 732a6a3

Please sign in to comment.