trie: small optimization of delete in fullNode case #22979 (#1069)

This commit is contained in:
Daniel Liu 2025-06-17 13:17:07 +08:00 committed by GitHub
parent 1f05c3e5fd
commit a41a92978d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -484,6 +484,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