From a7e8aec3d9bcc874d93a8cd0784611159a1182bd Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Sat, 15 Jun 2019 10:15:49 -0700 Subject: [PATCH] Allow to end markers early Summary: Adds the ability to `MarkerSection` to end the marker before it goes out of scope. This unlocks two scenarios: - reuse the data associated with a marker after ending it. - end markers in the middle of a function without adding arbitrary blocks. Reviewed By: SidharthGuglani Differential Revision: D15837840 fbshipit-source-id: c0afaeeabd169c65189b5028be54ea7dac3e3b84 --- yoga/Yoga.cpp | 15 ++++++--------- yoga/instrumentation.h | 4 +++- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index cbdb9561..0dfcb6e5 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -4026,9 +4026,7 @@ void YGNodeCalculateLayoutWithContext( #ifdef YG_ENABLE_EVENTS Event::publish(node, {layoutContext}); #endif - // unique pointer to allow ending the marker early - std::unique_ptr> marker{ - new marker::MarkerSection{node}}; + marker::MarkerSection marker{node}; // Increment the generation count. This will force the recursive routine to // visit all dirty nodes at least once. Subsequent visits will be skipped if @@ -4087,7 +4085,7 @@ void YGNodeCalculateLayoutWithContext( true, "initial", node->getConfig(), - marker->data, + marker.data, layoutContext)) { node->setPosition( node->getLayout().direction, ownerWidth, ownerHeight, ownerWidth); @@ -4104,12 +4102,11 @@ void YGNodeCalculateLayoutWithContext( #endif } -#ifdef YG_ENABLE_EVENTS - Event::publish(node, {layoutContext, &marker->data}); -#endif + marker.end(); - // end marker here - marker = nullptr; +#ifdef YG_ENABLE_EVENTS + Event::publish(node, {layoutContext, &marker.data}); +#endif // We want to get rid off `useLegacyStretchBehaviour` from YGConfig. But we // aren't sure whether client's of yoga have gotten rid off this flag or not. diff --git a/yoga/instrumentation.h b/yoga/instrumentation.h index e15f2fb1..369703a1 100644 --- a/yoga/instrumentation.h +++ b/yoga/instrumentation.h @@ -19,11 +19,13 @@ private: public: MarkerSection(YGNodeRef node) : MarkerSection{node, node->getConfig()} {} - ~MarkerSection() { + void end() { if (endMarker_) { endMarker_(MarkerType, node_, markerData(&data), userData_); + endMarker_ = nullptr; } } + ~MarkerSection() { end(); } typename Data::type data = {};