refactor(miniscript): Destroy nodes one full subs-vector at a time
This commit is contained in:
1 file changed
+8
-7
@@ -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)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user