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:
@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user