From 853c667eb5a66612c33e0786ab6c458dcaee6133 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 --- ReactCommon/yoga/yoga/Yoga.cpp | 13 +++++-------- ReactCommon/yoga/yoga/instrumentation.h | 4 +++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index cbdb956118f26d..0dfcb6e54fc216 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/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,13 +4102,12 @@ void YGNodeCalculateLayoutWithContext( #endif } + marker.end(); + #ifdef YG_ENABLE_EVENTS - Event::publish(node, {layoutContext, &marker->data}); + Event::publish(node, {layoutContext, &marker.data}); #endif - // end marker here - marker = nullptr; - // 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. // So logging this in YGLayout would help to find out the call sites depending diff --git a/ReactCommon/yoga/yoga/instrumentation.h b/ReactCommon/yoga/yoga/instrumentation.h index e15f2fb1e45d79..369703a1544c04 100644 --- a/ReactCommon/yoga/yoga/instrumentation.h +++ b/ReactCommon/yoga/yoga/instrumentation.h @@ -19,11 +19,13 @@ class MarkerSection { 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 = {};