From a41a92978ddeaf8c789b42936861578b93403f3f Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Tue, 17 Jun 2025 13:17:07 +0800 Subject: [PATCH] trie: small optimization of delete in fullNode case #22979 (#1069) --- trie/trie.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/trie/trie.go b/trie/trie.go index a1529ba4d2..45a2d6aecb 100644 --- a/trie/trie.go +++ b/trie/trie.go @@ -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