From cd5324378dab3fef8da28dde2e841e4d8d9d4b80 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Fri, 28 Jun 2019 09:53:15 -0700 Subject: [PATCH] Move `YG_ENABLE_EVENTS` checks to `event.h` Summary: Instead of checking whether `YG_ENABLE_EVENTS` is defined for every publish, we simply wrap the body of the `publish` function macro that delegates to the method that actually publishes the event. This way we get 1. easier to write code where we publish events 2. more type safety when editing, enabling editors/IDEs to show errors without knowing about `YG_ENABLE_EVENTS` Reviewed By: SidharthGuglani Differential Revision: D16049888 fbshipit-source-id: cbf362d6f7be5053c3f377125d303b7137d6a241 --- yoga/Yoga.cpp | 19 ------------------- yoga/event/event.h | 2 ++ 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 5d6a258b..d23d7129 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -213,9 +213,7 @@ WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) { const YGNodeRef node = new YGNode{config}; YGAssertWithConfig( config, node != nullptr, "Could not allocate memory for node"); -#ifdef YG_ENABLE_EVENTS Event::publish(node, {config}); -#endif return node; } @@ -235,9 +233,7 @@ YGNodeRef YGNodeClone(YGNodeRef oldNode) { oldNode->getConfig(), node != nullptr, "Could not allocate memory for node"); -#ifdef YG_ENABLE_EVENTS Event::publish(node, {node->getConfig()}); -#endif node->setOwner(nullptr); return node; } @@ -256,9 +252,7 @@ static YGNodeRef YGNodeDeepClone(YGNodeRef oldNode) { auto config = YGConfigClone(*oldNode->getConfig()); auto node = new YGNode{*oldNode, config}; node->setOwner(nullptr); -#ifdef YG_ENABLE_EVENTS Event::publish(node, {node->getConfig()}); -#endif YGVector vec = YGVector(); vec.reserve(oldNode->getChildren().size()); @@ -286,9 +280,7 @@ void YGNodeFree(const YGNodeRef node) { } node->clearChildren(); -#ifdef YG_ENABLE_EVENTS Event::publish(node, {node->getConfig()}); -#endif delete node; } @@ -1637,9 +1629,7 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( ownerWidth), YGDimensionHeight); } else { -#ifdef YG_ENABLE_EVENTS Event::publish(node); -#endif // Measure the text under the current constraints. const YGSize measuredSize = marker::MarkerSection::wrap( @@ -1653,7 +1643,6 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( layoutMarkerData.measureCallbacks += 1; -#ifdef YG_ENABLE_EVENTS Event::publish( node, {layoutContext, @@ -1663,7 +1652,6 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( heightMeasureMode, measuredSize.width, measuredSize.height}); -#endif node->setLayoutMeasuredDimension( YGNodeBoundAxis( @@ -3956,7 +3944,6 @@ bool YGLayoutNodeInternal( layout->generationCount = generationCount; -#ifdef YG_ENABLE_EVENTS LayoutType layoutType; if (performLayout) { layoutType = !needToVisitNode && cachedResults == &layout->cachedLayout @@ -3967,7 +3954,6 @@ bool YGLayoutNodeInternal( : LayoutType::kMeasure; } Event::publish(node, {layoutType, layoutContext}); -#endif return (needToVisitNode || cachedResults == nullptr); } @@ -4076,9 +4062,7 @@ void YGNodeCalculateLayoutWithContext( const YGDirection ownerDirection, void* layoutContext) { -#ifdef YG_ENABLE_EVENTS Event::publish(node, {layoutContext}); -#endif marker::MarkerSection marker{node}; // Increment the generation count. This will force the recursive routine to @@ -4158,10 +4142,7 @@ void YGNodeCalculateLayoutWithContext( } marker.end(); - -#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/event/event.h b/yoga/event/event.h index 69911a2b..1f2cf90f 100644 --- a/yoga/event/event.h +++ b/yoga/event/event.h @@ -60,7 +60,9 @@ struct Event { template static void publish(const YGNode& node, const TypedData& eventData = {}) { +#ifdef YG_ENABLE_EVENTS publish(node, E, Data{eventData}); +#endif } template