[poincare] TreeNode have a zero refcount by default

This commit is contained in:
Romain Goyet
2018-08-10 15:37:50 +02:00
parent 5b9950ec0e
commit 29f5763c7d
4 changed files with 4 additions and 10 deletions

View File

@@ -36,13 +36,6 @@ public:
m_referenceCounter = refCount;
}
void deepResetReferenceCounter() { //TODO make this method private with friends that can access it
setReferenceCounter(0);
for (TreeNode * t : depthFirstChildren()) {
t->setReferenceCounter(1);
}
}
// Ghost
virtual bool isGhost() const { return false; }

View File

@@ -81,6 +81,7 @@ void TreeByReference::buildGhostChildren() {
renameNode(copy, false);
for (TreeNode * child : copy->depthFirstChildren()) {
renameNode(child, false);
child->retain();
}
return copy;
}

View File

@@ -24,7 +24,6 @@ TreeByReference TreeByReference::clone() const {
return TreeByReference(TreePool::sharedPool()->node(allocationFailureNodeId));
}
TreeNode * nodeCopy = TreePool::sharedPool()->deepCopy(myNode);
nodeCopy->deepResetReferenceCounter();
return TreeByReference(nodeCopy);
}
@@ -97,6 +96,7 @@ void TreeByReference::replaceWithAllocationFailureInPlace(int currentNumberOfChi
//TODO static assert that the size is smaller
TreeNode * newAllocationFailureNode = TreePool::sharedPool()->deepCopy(staticAllocFailNode);
newAllocationFailureNode->rename(m_identifier, true);
newAllocationFailureNode->retain();
if (p.isDefined()) {
assert(indexInParentNode >= 0);
/* Set the refCount to previousRefCount-1 because the previous parent is

View File

@@ -30,7 +30,7 @@ void TreeNode::rename(int identifier, bool unregisterPreviousIdentifier) {
TreePool::sharedPool()->unregisterNode(this);
}
m_identifier = identifier;
m_referenceCounter = 1;
m_referenceCounter = 0;
TreePool::sharedPool()->registerNode(this);
}
@@ -187,7 +187,7 @@ bool TreeNode::hasSibling(const TreeNode * e) const {
TreeNode::TreeNode() :
m_identifier(TreePool::NoNodeIdentifier),
m_referenceCounter(1)
m_referenceCounter(0)
{
}