From 0a9e652bdd031d53d712e2e9610fb608bfa54ff1 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Mon, 8 Jan 2018 02:48:35 -0800 Subject: [PATCH] Move markDirtyInternal as a method in YGNode Reviewed By: emilsjolander Differential Revision: D6611287 fbshipit-source-id: 54402145d51ea717553ea136be739b9880a79817 --- ReactCommon/yoga/yoga/YGNode.cpp | 12 +++++++++ ReactCommon/yoga/yoga/YGNode.h | 1 + ReactCommon/yoga/yoga/Yoga.cpp | 46 ++++++++++++-------------------- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/ReactCommon/yoga/yoga/YGNode.cpp b/ReactCommon/yoga/yoga/YGNode.cpp index f76a1cb6d4cbc3..908bfd98ecd8bc 100644 --- a/ReactCommon/yoga/yoga/YGNode.cpp +++ b/ReactCommon/yoga/yoga/YGNode.cpp @@ -379,6 +379,8 @@ YGNode::~YGNode() { // deallocate here } +// Other Methods + void YGNode::cloneChildrenIfNeeded() { // YGNodeRemoveChild in yoga.cpp has a forked variant of this algorithm // optimized for deletions. @@ -409,3 +411,13 @@ void YGNode::cloneChildrenIfNeeded() { } } } + +void YGNode::markDirtyAndPropogate() { + if (!isDirty_) { + isDirty_ = true; + setLayoutComputedFlexBasis(YGUndefined); + if (parent_) { + parent_->markDirtyAndPropogate(); + } + } +} diff --git a/ReactCommon/yoga/yoga/YGNode.h b/ReactCommon/yoga/yoga/YGNode.h index 52337dda90f8f2..c0761ed7e58d3e 100644 --- a/ReactCommon/yoga/yoga/YGNode.h +++ b/ReactCommon/yoga/yoga/YGNode.h @@ -121,4 +121,5 @@ struct YGNode { // Other methods void cloneChildrenIfNeeded(); + void markDirtyAndPropogate(); }; diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index 9712e65c8b791d..ae465e57d7f657 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -60,8 +60,6 @@ const YGValue YGValueZero = {.value = 0, .unit = YGUnitPoint}; const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined}; const YGValue YGValueAuto = {YGUndefined, YGUnitAuto}; -static void YGNodeMarkDirtyInternal(const YGNodeRef node); - #ifdef ANDROID #include static int YGAndroidLog(const YGConfigRef config, @@ -338,16 +336,6 @@ void YGConfigCopy(const YGConfigRef dest, const YGConfigRef src) { memcpy(dest, src, sizeof(YGConfig)); } -static void YGNodeMarkDirtyInternal(const YGNodeRef node) { - if (!node->isDirty()) { - node->setDirty(true); - node->setLayoutComputedFlexBasis(YGUndefined); - if (node->getParent()) { - YGNodeMarkDirtyInternal(node->getParent()); - } - } -} - void YGNodeInsertChild(const YGNodeRef node, const YGNodeRef child, const uint32_t index) { YGAssertWithNode( node, @@ -361,7 +349,7 @@ void YGNodeInsertChild(const YGNodeRef node, const YGNodeRef child, const uint32 node->cloneChildrenIfNeeded(); node->insertChild(child, index); child->setParent(node); - YGNodeMarkDirtyInternal(node); + node->markDirtyAndPropogate(); } void YGNodeRemoveChild(const YGNodeRef parent, const YGNodeRef excludedChild) { @@ -381,7 +369,7 @@ void YGNodeRemoveChild(const YGNodeRef parent, const YGNodeRef excludedChild) { excludedChild->setLayout( YGNode().getLayout()); // layout is no longer valid excludedChild->setParent(nullptr); - YGNodeMarkDirtyInternal(parent); + parent->markDirtyAndPropogate(); } return; } @@ -397,7 +385,7 @@ void YGNodeRemoveChild(const YGNodeRef parent, const YGNodeRef excludedChild) { // Ignore the deleted child. Don't reset its layout or parent since it is still valid // in the other parent. However, since this parent has now changed, we need to mark it // as dirty. - YGNodeMarkDirtyInternal(parent); + parent->markDirtyAndPropogate(); continue; } const YGNodeRef newChild = YGNodeClone(oldChild); @@ -429,12 +417,12 @@ void YGNodeRemoveAllChildren(const YGNodeRef parent) { oldChild->setParent(nullptr); } parent->clearChildren(); - YGNodeMarkDirtyInternal(parent); + parent->markDirtyAndPropogate(); return; } // Otherwise, we are not the owner of the child set. We don't have to do anything to clear it. parent->setChildren(YGVector()); - YGNodeMarkDirtyInternal(parent); + parent->markDirtyAndPropogate(); } YGNodeRef YGNodeGetChild(const YGNodeRef node, const uint32_t index) { @@ -459,13 +447,13 @@ void YGNodeMarkDirty(const YGNodeRef node) { "Only leaf nodes with custom measure functions" "should manually mark themselves as dirty"); - YGNodeMarkDirtyInternal(node); + node->markDirtyAndPropogate(); } void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) { if (!(dstNode->getStyle() == srcNode->getStyle())) { dstNode->setStyle(srcNode->getStyle()); - YGNodeMarkDirtyInternal(dstNode); + dstNode->markDirtyAndPropogate(); } } @@ -521,7 +509,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) { YGStyle style = node->getStyle(); \ style.instanceName = paramName; \ node->setStyle(style); \ - YGNodeMarkDirtyInternal(node); \ + node->markDirtyAndPropogate(); \ } \ } @@ -538,7 +526,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) { YGStyle style = node->getStyle(); \ style.instanceName = value; \ node->setStyle(style); \ - YGNodeMarkDirtyInternal(node); \ + node->markDirtyAndPropogate(); \ } \ } \ \ @@ -556,7 +544,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) { \ style.instanceName = value; \ node->setStyle(style); \ - YGNodeMarkDirtyInternal(node); \ + node->markDirtyAndPropogate(); \ } \ } @@ -573,7 +561,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) { YGStyle style = node->getStyle(); \ style.instanceName = value; \ node->setStyle(style); \ - YGNodeMarkDirtyInternal(node); \ + node->markDirtyAndPropogate(); \ } \ } \ \ @@ -586,7 +574,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) { style.instanceName.unit = \ YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPercent; \ node->setStyle(style); \ - YGNodeMarkDirtyInternal(node); \ + node->markDirtyAndPropogate(); \ } \ } \ \ @@ -596,7 +584,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) { style.instanceName.value = YGUndefined; \ style.instanceName.unit = YGUnitAuto; \ node->setStyle(style); \ - YGNodeMarkDirtyInternal(node); \ + node->markDirtyAndPropogate(); \ } \ } @@ -631,7 +619,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) { style.instanceName[edge].value = YGUndefined; \ style.instanceName[edge].unit = YGUnitAuto; \ node->setStyle(style); \ - YGNodeMarkDirtyInternal(node); \ + node->markDirtyAndPropogate(); \ } \ } @@ -649,7 +637,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) { YGStyle style = node->getStyle(); \ style.instanceName[edge] = value; \ node->setStyle(style); \ - YGNodeMarkDirtyInternal(node); \ + node->markDirtyAndPropogate(); \ } \ } \ \ @@ -666,7 +654,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) { YGStyle style = node->getStyle(); \ style.instanceName[edge] = value; \ node->setStyle(style); \ - YGNodeMarkDirtyInternal(node); \ + node->markDirtyAndPropogate(); \ } \ } \ \ @@ -688,7 +676,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) { YGStyle style = node->getStyle(); \ style.instanceName[edge] = value; \ node->setStyle(style); \ - YGNodeMarkDirtyInternal(node); \ + node->markDirtyAndPropogate(); \ } \ } \ \