From af1fe62ae0f83e77304d29ba2dc68f25e05e50ad Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Sun, 10 May 2020 13:26:08 -0700 Subject: [PATCH] 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 --- ReactCommon/fabric/uimanager/UIManager.cpp | 12 ++++++------ ReactCommon/fabric/uimanager/UIManager.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ReactCommon/fabric/uimanager/UIManager.cpp b/ReactCommon/fabric/uimanager/UIManager.cpp index e87280c58cd..7258d9ca46f 100644 --- a/ReactCommon/fabric/uimanager/UIManager.cpp +++ b/ReactCommon/fabric/uimanager/UIManager.cpp @@ -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(newestShadowNode->get()); + traitCast(newestShadowNode.get()); auto layoutableAncestorShadowNode = traitCast(ancestorShadowNode); diff --git a/ReactCommon/fabric/uimanager/UIManager.h b/ReactCommon/fabric/uimanager/UIManager.h index 956f459f935..51131dd98de 100644 --- a/ReactCommon/fabric/uimanager/UIManager.h +++ b/ReactCommon/fabric/uimanager/UIManager.h @@ -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; /*