refactor(miniscript): Destroy nodes one full subs-vector at a time

This commit is contained in:
Hodlinator committed 2026-01-20 22:41:25 +01:00
1 parent 50cab8570e
commit 198bbaee49
1 file changed
+8 -7
+8 -7
View File
@@ -552,14 +552,15 @@ public:
// Destroy the subexpressions iteratively after moving out their // Destroy the subexpressions iteratively after moving out their
// subexpressions to avoid a stack-overflow due to recursive calls to // subexpressions to avoid a stack-overflow due to recursive calls to
// the subs' destructors. // the subs' destructors.
while (!subs.empty()) { std::vector<std::vector<Node>> queue;
auto node = std::move(subs.back()); queue.push_back(std::move(subs));
subs.pop_back(); do {
while (!node.subs.empty()) { auto flattening{std::move(queue.back())};
subs.push_back(std::move(node.subs.back())); queue.pop_back();
node.subs.pop_back(); for (Node& n : flattening) {
if (!n.subs.empty()) queue.push_back(std::move(n.subs));
} }
} } while (!queue.empty());
} }
// NOLINTEND(misc-no-recursion) // NOLINTEND(misc-no-recursion)