Fabric: New approach to manage Yoga's parent/owner references

Summary:
The modern Concurent Yoga's concept is:
We have to set parent/owner reference as part of `appendChild` process only if the current reference to parent/owner is `null`.
The motivation:
 * Null-parent indicates that this node was not attached to anything yet;
 * So, in this case there is no any concurrent memory access because we always create and (first time) attach the node on same thread;
 * Simmetrical parent-child relationship indicates that we don't need to (re)clone assosiated ShadowNode (nor Yoga node).

Reviewed By: mdvacca

Differential Revision: D7467791

fbshipit-source-id: 9a7f517380fde3bb00272de18fd5dc13edb52071
This commit is contained in:
Valentin Shergin 2018-04-10 12:45:53 -07:00 committed by Facebook Github Bot
parent 5dca3e7c74
commit ef6b916e48
1 changed files with 13 additions and 1 deletions

View File

@ -97,6 +97,11 @@ void YogaLayoutableShadowNode::appendChild(SharedYogaLayoutableShadowNode child)
auto nonConstYogaNode = std::const_pointer_cast<YGNode>(yogaNode_);
auto nonConstChildYogaNode = std::const_pointer_cast<YGNode>(child->yogaNode_);
nonConstYogaNode->insertChild(nonConstChildYogaNode.get(), nonConstYogaNode->getChildrenCount());
if (nonConstChildYogaNode->getParent() == nullptr) {
child->ensureUnsealed();
nonConstChildYogaNode->setParent(nonConstYogaNode.get());
}
}
void YogaLayoutableShadowNode::layout(LayoutContext layoutContext) {
@ -211,7 +216,14 @@ void YogaLayoutableShadowNode::setYogaNodeChildrenBasedOnShadowNodeChildren(YGNo
continue;
}
yogaNodeChildren.push_back((YGNode *)yogaLayoutableShadowNode->yogaNode_.get());
YGNode *yogaNodeChild = (YGNode *)yogaLayoutableShadowNode->yogaNode_.get();
yogaNodeChildren.push_back(yogaNodeChild);
if (yogaNodeChild->getParent() == nullptr) {
yogaLayoutableShadowNode->ensureUnsealed();
yogaNodeChild->setParent(&yogaNode);
}
}
yogaNode.setChildren(yogaNodeChildren);