From 80258b530d1b6334de3d4e35e361d356ca053cee Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Tue, 21 May 2019 06:02:19 -0700 Subject: [PATCH] Remove `YGNode::setAndPropogateUseLegacyFlag` Summary: `YGNode::setAndPropogateUseLegacyFlag` was only used for debugging purposes. Here, we replace it with a free function in `Yoga.cpp`. Now that we have events, the diffing functionality should go into a separate debugging package and be implemented in terms of an event listener. Let's do that as soon as we can support multiple listeners. Reviewed By: SidharthGuglani Differential Revision: D15316863 fbshipit-source-id: db929eba7c2de8aa1550e362dd2c175929c0070e --- ReactCommon/yoga/yoga/YGNode.cpp | 7 ------ ReactCommon/yoga/yoga/YGNode.h | 1 - ReactCommon/yoga/yoga/Yoga.cpp | 37 +++++++++++++++++++------------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/ReactCommon/yoga/yoga/YGNode.cpp b/ReactCommon/yoga/yoga/YGNode.cpp index 172da8713d5..81a4216eb66 100644 --- a/ReactCommon/yoga/yoga/YGNode.cpp +++ b/ReactCommon/yoga/yoga/YGNode.cpp @@ -539,13 +539,6 @@ bool YGNode::didUseLegacyFlag() { return didUseLegacyFlag; } -void YGNode::setAndPropogateUseLegacyFlag(bool useLegacyFlag) { - config_->useLegacyStretchBehaviour = useLegacyFlag; - for_each(children_.begin(), children_.end(), [=](YGNodeRef childNode) { - childNode->getConfig()->useLegacyStretchBehaviour = useLegacyFlag; - }); -} - void YGNode::setLayoutDoesLegacyFlagAffectsLayout( bool doesLegacyFlagAffectsLayout) { layout_.doesLegacyStretchFlagAffectsLayout = doesLegacyFlagAffectsLayout; diff --git a/ReactCommon/yoga/yoga/YGNode.h b/ReactCommon/yoga/yoga/YGNode.h index d368bde0356..e5f1da3ca5b 100644 --- a/ReactCommon/yoga/yoga/YGNode.h +++ b/ReactCommon/yoga/yoga/YGNode.h @@ -292,7 +292,6 @@ public: const float mainSize, const float crossSize, const float ownerWidth); - void setAndPropogateUseLegacyFlag(bool useLegacyFlag); void setLayoutDoesLegacyFlagAffectsLayout(bool doesLegacyFlagAffectsLayout); void setLayoutDidUseLegacyFlag(bool didUseLegacyFlag); void markDirtyAndPropogateDownwards(); diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index bcca97951bb..c4544ed95a7 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -3992,6 +3992,13 @@ static void YGRoundToPixelGrid( } } +static void unsetUseLegacyFlagRecursively(YGNodeRef node) { + node->getConfig()->useLegacyStretchBehaviour = false; + for (auto child : node->getChildren()) { + unsetUseLegacyFlagRecursively(child); + } +} + void YGNodeCalculateLayoutWithContext( const YGNodeRef node, const float ownerWidth, @@ -4096,16 +4103,16 @@ void YGNodeCalculateLayoutWithContext( // run experiments. if (node->getConfig()->shouldDiffLayoutWithoutLegacyStretchBehaviour && node->didUseLegacyFlag()) { - const YGNodeRef originalNode = YGNodeDeepClone(node); - originalNode->resolveDimension(); + const YGNodeRef nodeWithoutLegacyFlag = YGNodeDeepClone(node); + nodeWithoutLegacyFlag->resolveDimension(); // Recursively mark nodes as dirty - originalNode->markDirtyAndPropogateDownwards(); + nodeWithoutLegacyFlag->markDirtyAndPropogateDownwards(); gCurrentGenerationCount++; // Rerun the layout, and calculate the diff - originalNode->setAndPropogateUseLegacyFlag(false); + unsetUseLegacyFlagRecursively(nodeWithoutLegacyFlag); YGMarkerLayoutData layoutMarkerData; if (YGLayoutNodeInternal( - originalNode, + nodeWithoutLegacyFlag, width, height, ownerDirection, @@ -4115,37 +4122,37 @@ void YGNodeCalculateLayoutWithContext( ownerHeight, true, "initial", - originalNode->getConfig(), + nodeWithoutLegacyFlag->getConfig(), layoutMarkerData, layoutContext)) { - originalNode->setPosition( - originalNode->getLayout().direction, + nodeWithoutLegacyFlag->setPosition( + nodeWithoutLegacyFlag->getLayout().direction, ownerWidth, ownerHeight, ownerWidth); YGRoundToPixelGrid( - originalNode, - originalNode->getConfig()->pointScaleFactor, + nodeWithoutLegacyFlag, + nodeWithoutLegacyFlag->getConfig()->pointScaleFactor, 0.0f, 0.0f); // Set whether the two layouts are different or not. auto neededLegacyStretchBehaviour = - !originalNode->isLayoutTreeEqualToNode(*node); + !nodeWithoutLegacyFlag->isLayoutTreeEqualToNode(*node); node->setLayoutDoesLegacyFlagAffectsLayout(neededLegacyStretchBehaviour); #ifdef DEBUG - if (originalNode->getConfig()->printTree) { + if (nodeWithoutLegacyFlag->getConfig()->printTree) { YGNodePrint( - originalNode, + nodeWithoutLegacyFlag, (YGPrintOptions)( YGPrintOptionsLayout | YGPrintOptionsChildren | YGPrintOptionsStyle)); } #endif } - YGConfigFreeRecursive(originalNode); - YGNodeFreeRecursive(originalNode); + YGConfigFreeRecursive(nodeWithoutLegacyFlag); + YGNodeFreeRecursive(nodeWithoutLegacyFlag); } }