mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-31 10:41:08 +00:00
refactor(miniscript): Destroy nodes one full subs-vector at a time
This commit is contained in:
parent
50cab8570e
commit
198bbaee49
@ -552,14 +552,15 @@ public:
|
||||
// Destroy the subexpressions iteratively after moving out their
|
||||
// subexpressions to avoid a stack-overflow due to recursive calls to
|
||||
// the subs' destructors.
|
||||
while (!subs.empty()) {
|
||||
auto node = std::move(subs.back());
|
||||
subs.pop_back();
|
||||
while (!node.subs.empty()) {
|
||||
subs.push_back(std::move(node.subs.back()));
|
||||
node.subs.pop_back();
|
||||
std::vector<std::vector<Node>> queue;
|
||||
queue.push_back(std::move(subs));
|
||||
do {
|
||||
auto flattening{std::move(queue.back())};
|
||||
queue.pop_back();
|
||||
for (Node& n : flattening) {
|
||||
if (!n.subs.empty()) queue.push_back(std::move(n.subs));
|
||||
}
|
||||
}
|
||||
} while (!queue.empty());
|
||||
}
|
||||
// NOLINTEND(misc-no-recursion)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user