Skip to content

Commit

Permalink
Allow to end markers early
Browse files Browse the repository at this point in the history
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
  • Loading branch information
davidaurelio authored and facebook-github-bot committed Jun 15, 2019
1 parent 3ce9ac6 commit 853c667
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 5 additions & 8 deletions ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4026,9 +4026,7 @@ void YGNodeCalculateLayoutWithContext(
#ifdef YG_ENABLE_EVENTS
Event::publish<Event::LayoutPassStart>(node, {layoutContext});
#endif
// unique pointer to allow ending the marker early
std::unique_ptr<marker::MarkerSection<YGMarkerLayout>> marker{
new marker::MarkerSection<YGMarkerLayout>{node}};
marker::MarkerSection<YGMarkerLayout> 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
Expand Down Expand Up @@ -4087,7 +4085,7 @@ void YGNodeCalculateLayoutWithContext(
true,
"initial",
node->getConfig(),
marker->data,
marker.data,
layoutContext)) {
node->setPosition(
node->getLayout().direction, ownerWidth, ownerHeight, ownerWidth);
Expand All @@ -4104,13 +4102,12 @@ void YGNodeCalculateLayoutWithContext(
#endif
}

marker.end();

#ifdef YG_ENABLE_EVENTS
Event::publish<Event::LayoutPassEnd>(node, {layoutContext, &marker->data});
Event::publish<Event::LayoutPassEnd>(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
Expand Down
4 changes: 3 additions & 1 deletion ReactCommon/yoga/yoga/instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ class MarkerSection {

public:
MarkerSection(YGNodeRef node) : MarkerSection{node, node->getConfig()} {}
~MarkerSection() {
void end() {

This comment has been minimized.

Copy link
@nnnnnoel

nnnnnoel Jun 17, 2019

move to private?

if (endMarker_) {
endMarker_(MarkerType, node_, markerData(&data), userData_);
endMarker_ = nullptr;
}
}
~MarkerSection() { end(); }

typename Data::type data = {};

Expand Down

0 comments on commit 853c667

Please sign in to comment.