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