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:
parent
5dca3e7c74
commit
ef6b916e48
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue