Skip to content

Commit 732a6a3

Browse files
Evolution404fjl
andauthored
trie: small optimization of delete in fullNode case (ethereum#22979)
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>
1 parent 7b6c836 commit 732a6a3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

trie/trie.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,14 @@ func (t *Trie) delete(n node, prefix, key []byte) (bool, node, error) {
405405
n.flags = t.newFlag()
406406
n.Children[key[0]] = nn
407407

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

0 commit comments

Comments
 (0)