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.