[llvm] [ADT] Fuse the two post-mutation tree walks in ImutAVLFactory (PR #208907)
Gábor Horváth via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 12 04:20:56 PDT 2026
================
@@ -460,11 +458,21 @@ class ImutAVLFactory {
return createNode(newLeft, getValue(oldTree), newRight);
}
- void recoverNodes() {
- for (unsigned i = 0, n = createdNodes.size(); i < n; ++i) {
- TreeTy *N = createdNodes[i];
- if (N->isMutable() && N->refCount == 0)
+ void recoverNodes(TreeTy *Result) {
+ // Mark Result's nodes immutable and reclaim the intermediates discarded
+ // during balancing, in one pass. Nodes are built bottom-up, so a node
+ // precedes its parents in createdNodes; visiting in reverse thus reaches
+ // each node only once its reference count is final. Unreferenced nodes are
+ // unreachable and destroyed; the rest belong to Result. Result is kept
+ // despite its zero count -- the caller has not taken ownership yet.
+ for (unsigned I = createdNodes.size(); I-- > 0;) {
----------------
Xazax-hun wrote:
Good point, much cleaner now, thanks!
https://github.com/llvm/llvm-project/pull/208907
More information about the llvm-commits
mailing list