[poincare] TreeHandle: the constructor from a identifier retains the

node if it has one
This commit is contained in:
Émilie Feral
2019-02-19 14:00:58 +01:00
committed by LeaNumworks
parent 3fc32d7c74
commit 55704b4e65
3 changed files with 7 additions and 5 deletions

View File

@@ -248,6 +248,7 @@ public:
protected:
static bool SimplificationHasBeenInterrupted();
Expression(const ExpressionNode * n) : TreeHandle(n) {}
Expression(int nodeIdentifier) : TreeHandle(nodeIdentifier) {}
template<typename U>
static Expression UntypedBuilderOneChild(Expression children) {
assert(children.type() == ExpressionNode::Type::Matrix);
@@ -284,7 +285,6 @@ protected:
}
/* Hierarchy */
Expression(int nodeIdentifier) : TreeHandle(nodeIdentifier) {}
Expression parent() const; // TODO try to inline
void defaultSetChildrenInPlace(Expression other);
void addChildAtIndexInPlace(TreeHandle t, int index, int currentNumberOfChildren) = delete;

View File

@@ -103,7 +103,11 @@ public:
protected:
/* Constructor */
TreeHandle(const TreeNode * node);
TreeHandle(int nodeIndentifier = TreeNode::NoNodeIdentifier) : m_identifier(nodeIndentifier) {}
TreeHandle(int nodeIndentifier = TreeNode::NoNodeIdentifier) : m_identifier(nodeIndentifier) {
if (hasNode(nodeIndentifier)) {
node()->retain();
}
}
// WARNING: if the children table is the result of a cast, the object downcasted has to be the same size as a TreeHandle.
static TreeHandle BuildWithBasicChildren(TreeNode * node, TreeHandle * children = nullptr, int numberOfChildren = 0);

View File

@@ -107,9 +107,7 @@ Integer::Integer(native_uint_t * digits, uint16_t numberOfDigits, bool negative)
TreeHandle h = TreeHandle::BuildWithBasicChildren(node);
/* Integer is a TreeHandle that keeps an extra integer. We cannot just cast
* the TreeHandle in Integer, we have to build a new Integer. To do so, we
* pilfer the TreeHandle identifier. We thus have to increment the node
* reference counter to prevent its destruction when we leave this scope. */
node->retain();
* pilfer the TreeHandle identifier. */
new (this) Integer(h.identifier(), negative);
}