From b9e5ebd64001352a569072a158ca4d8d30ef8f1c Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Wed, 26 Feb 2020 22:03:14 -0800 Subject: [PATCH] Fabric: Using `traitCast` in Differentiator Summary: The Diffing is one of the hottest pieces of Fabric. Removing dynamic_cast here should improve perf. See the previous diff for more details. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D20052030 fbshipit-source-id: 27fd9f34f2a1f9d22b9da6b1e3c1a2982045c07a --- ReactCommon/fabric/mounting/Differentiator.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ReactCommon/fabric/mounting/Differentiator.cpp b/ReactCommon/fabric/mounting/Differentiator.cpp index e7559c78790..05e1cd8f5f4 100644 --- a/ReactCommon/fabric/mounting/Differentiator.cpp +++ b/ReactCommon/fabric/mounting/Differentiator.cpp @@ -83,11 +83,13 @@ static void sliceChildShadowNodeViewPairsRecursively( ShadowViewNodePair::List &pairList, Point layoutOffset, ShadowNode const &shadowNode) { - for (auto const &childShadowNode : shadowNode.getChildren()) { - auto shadowView = ShadowView(*childShadowNode); + for (auto const &sharedChildShadowNode : shadowNode.getChildren()) { + auto &childShadowNode = *sharedChildShadowNode; + auto shadowView = ShadowView(childShadowNode); + + auto layoutableShadowNode = + traitCast(&childShadowNode); - auto const layoutableShadowNode = - dynamic_cast(childShadowNode.get()); #ifndef ANDROID // New approach (iOS): // Non-view components are treated as layout-only views (they aren't @@ -102,10 +104,10 @@ static void sliceChildShadowNodeViewPairsRecursively( sliceChildShadowNodeViewPairsRecursively( pairList, layoutOffset + shadowView.layoutMetrics.frame.origin, - *childShadowNode); + childShadowNode); } else { shadowView.layoutMetrics.frame.origin += layoutOffset; - pairList.push_back({shadowView, childShadowNode.get()}); + pairList.push_back({shadowView, &childShadowNode}); } } }