From 5a65261a55c4cb87f1a3bd891f16ab30a2dfee0e Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Thu, 6 Dec 2018 07:35:10 -0800 Subject: [PATCH] Remove templates for setting/getting style properties Summary: @public Replaces the `StyleProp` template with a simple setter macro / inlined getter code. The template was introduced to replace more extensive macros that would generate function signatures, too. Here, we keep the spirit of that change by only generating function bodies. Reviewed By: SidharthGuglani Differential Revision: D13233687 fbshipit-source-id: 218a7d5edb489b43a66c8c9d6156f74feefd2227 --- yoga/Yoga.cpp | 63 ++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index b5320c63..5a5da8b0 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -591,19 +591,6 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) { namespace { -template -struct StyleProp { - static T get(YGNodeRef node) { - return node->getStyle().*P; - } - static void set(YGNodeRef node, T newValue) { - if (node->getStyle().*P != newValue) { - node->getStyle().*P = newValue; - node->markDirtyAndPropogate(); - } - } -}; - struct Value { template static YGValue create(float value) { @@ -763,84 +750,88 @@ struct DimensionProp { return node->getLayout().instanceName[edge]; \ } -void YGNodeStyleSetDirection( - const YGNodeRef node, - const YGDirection direction) { - StyleProp::set(node, direction); +#define YG_NODE_STYLE_SET(node, property, value) \ + if (node->getStyle().property != value) { \ + node->getStyle().property = value; \ + node->markDirtyAndPropogate(); \ + } + +void YGNodeStyleSetDirection(const YGNodeRef node, const YGDirection value) { + YG_NODE_STYLE_SET(node, direction, value); } YGDirection YGNodeStyleGetDirection(const YGNodeRef node) { - return StyleProp::get(node); + return node->getStyle().direction; } void YGNodeStyleSetFlexDirection( const YGNodeRef node, const YGFlexDirection flexDirection) { - StyleProp::set(node, flexDirection); + YG_NODE_STYLE_SET(node, flexDirection, flexDirection); } YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeRef node) { - return StyleProp::get(node); + return node->getStyle().flexDirection; } void YGNodeStyleSetJustifyContent( const YGNodeRef node, const YGJustify justifyContent) { - StyleProp::set(node, justifyContent); + YG_NODE_STYLE_SET(node, justifyContent, justifyContent); } YGJustify YGNodeStyleGetJustifyContent(const YGNodeRef node) { - return StyleProp::get(node); + return node->getStyle().justifyContent; } void YGNodeStyleSetAlignContent( const YGNodeRef node, const YGAlign alignContent) { - StyleProp::set(node, alignContent); + YG_NODE_STYLE_SET(node, alignContent, alignContent); } YGAlign YGNodeStyleGetAlignContent(const YGNodeRef node) { - return StyleProp::get(node); + return node->getStyle().alignContent; } void YGNodeStyleSetAlignItems(const YGNodeRef node, const YGAlign alignItems) { - StyleProp::set(node, alignItems); + YG_NODE_STYLE_SET(node, alignItems, alignItems); } YGAlign YGNodeStyleGetAlignItems(const YGNodeRef node) { - return StyleProp::get(node); + return node->getStyle().alignItems; } void YGNodeStyleSetAlignSelf(const YGNodeRef node, const YGAlign alignSelf) { - StyleProp::set(node, alignSelf); + YG_NODE_STYLE_SET(node, alignSelf, alignSelf); } YGAlign YGNodeStyleGetAlignSelf(const YGNodeRef node) { - return StyleProp::get(node); + return node->getStyle().alignSelf; } void YGNodeStyleSetPositionType( const YGNodeRef node, const YGPositionType positionType) { - StyleProp::set(node, positionType); + YG_NODE_STYLE_SET(node, positionType, positionType); } YGPositionType YGNodeStyleGetPositionType(const YGNodeRef node) { - return StyleProp::get(node); + return node->getStyle().positionType; } void YGNodeStyleSetFlexWrap(const YGNodeRef node, const YGWrap flexWrap) { - StyleProp::set(node, flexWrap); + YG_NODE_STYLE_SET(node, flexWrap, flexWrap); } YGWrap YGNodeStyleGetFlexWrap(const YGNodeRef node) { - return StyleProp::get(node); + return node->getStyle().flexWrap; } void YGNodeStyleSetOverflow(const YGNodeRef node, const YGOverflow overflow) { - StyleProp::set(node, overflow); + YG_NODE_STYLE_SET(node, overflow, overflow); } YGOverflow YGNodeStyleGetOverflow(const YGNodeRef node) { - return StyleProp::get(node); + return node->getStyle().overflow; } void YGNodeStyleSetDisplay(const YGNodeRef node, const YGDisplay display) { - StyleProp::set(node, display); + YG_NODE_STYLE_SET(node, display, display); } YGDisplay YGNodeStyleGetDisplay(const YGNodeRef node) { - return StyleProp::get(node); + return node->getStyle().display; } // TODO(T26792433): Change the API to accept YGFloatOptional.