A bit closer to RAII on the doctree.

It should be an external vector of ownership...  The recursion
through the stack for deletion has the potential to be a
serious problem.
This commit is contained in:
2025-04-23 20:24:50 -04:00
parent f702ca398d
commit 6af638059b

View File

@ -29,9 +29,9 @@ class DoctreeNode {
~DoctreeNode () {
dFree ((void*) id);
while (lastChild) {
DoctreeNode *n = lastChild;
lastChild = lastChild->sibling;
delete n;
std::unique_ptr< DoctreeNode > deleter;
deleter.reset( lastChild ); // It's a step toward RAII
lastChild = deleter->sibling;
}
}
};
@ -57,13 +57,13 @@ class Doctree {
~Doctree ()= default;
DoctreeNode *push () {
DoctreeNode *dn = new DoctreeNode ();
auto dn= std::make_unique< DoctreeNode >();
dn->parent = topNode;
dn->sibling = dn->parent->lastChild;
dn->parent->lastChild = dn;
dn->num = num++;
topNode = dn;
return dn;
dn->parent->lastChild = dn.get();
topNode = dn.get();
return dn.release();
};
void pop () {