Fabric: Changes in UIManager::getNewestCloneOfShadowNode to make it safer

Summary:
There is no need to use a raw pointer to a shared pointer as a return value of `UIManager::getNewestCloneOfShadowNode`. If it would be a very hot path, we could you a raw pointer to the node instead but it's not a hot path.
Prooving that using a raw pointer here is safe is quite complex (and I don't know if it's safe or not). So, I changed it to just a shared pointer.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: JoshuaGross

Differential Revision: D21464833

fbshipit-source-id: 813a3c9fca0147afb322db6855a0ce8fd2d47909
This commit is contained in:
Valentin Shergin 2020-05-10 13:26:08 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 03ef81bfa2
Коммит af1fe62ae0
2 изменённых файлов: 7 добавлений и 7 удалений

Просмотреть файл

@ -124,13 +124,13 @@ void UIManager::clearJSResponder() const {
}
}
ShadowNode::Shared const *UIManager::getNewestCloneOfShadowNode(
ShadowNode::Shared UIManager::getNewestCloneOfShadowNode(
ShadowNode const &shadowNode) const {
auto findNewestChildInParent =
[&](auto const &parentNode) -> ShadowNode::Shared const * {
[&](auto const &parentNode) -> ShadowNode::Shared {
for (auto const &child : parentNode.getChildren()) {
if (ShadowNode::sameFamily(*child, shadowNode)) {
return &child;
return child;
}
}
return nullptr;
@ -156,7 +156,7 @@ ShadowNode::Shared UIManager::findNodeAtPoint(
ShadowNode::Shared const &node,
Point point) const {
return LayoutableShadowNode::findNodeAtPoint(
*getNewestCloneOfShadowNode(*node), point);
getNewestCloneOfShadowNode(*node), point);
}
void UIManager::setNativeProps(
@ -201,7 +201,7 @@ LayoutMetrics UIManager::getRelativeLayoutMetrics(
true);
});
} else {
ancestorShadowNode = getNewestCloneOfShadowNode(*ancestorShadowNode)->get();
ancestorShadowNode = getNewestCloneOfShadowNode(*ancestorShadowNode).get();
}
// Get latest version of both the ShadowNode and its ancestor.
@ -211,7 +211,7 @@ LayoutMetrics UIManager::getRelativeLayoutMetrics(
auto newestShadowNode = getNewestCloneOfShadowNode(shadowNode);
auto layoutableShadowNode =
traitCast<LayoutableShadowNode const *>(newestShadowNode->get());
traitCast<LayoutableShadowNode const *>(newestShadowNode.get());
auto layoutableAncestorShadowNode =
traitCast<LayoutableShadowNode const *>(ancestorShadowNode);

Просмотреть файл

@ -92,7 +92,7 @@ class UIManager final : public ShadowTreeDelegate {
ShadowNode::Shared const &shadowNode,
Point point) const;
ShadowNode::Shared const *getNewestCloneOfShadowNode(
ShadowNode::Shared getNewestCloneOfShadowNode(
ShadowNode const &shadowNode) const;
/*