From 03377ac3225863e610402b155eb0572e7a0c24d8 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Fri, 17 Aug 2018 03:56:39 -0700 Subject: [PATCH] Replace point setter in `YG_NODE_STYLE_PROPERTY_UNIT_IMPL` macro with template code Reviewed By: astreet Differential Revision: D8874735 fbshipit-source-id: 77fa1ceb2eaff6a0e415ef939e55aa22bc3d6099 --- ReactCommon/yoga/yoga/Yoga.cpp | 37 +++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index 6d3cfa70f..03185fb31 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -604,6 +604,16 @@ struct StyleProp { } }; +struct Value { + template + static YGValue create(float value) { + return { + YGFloatSanitize(value), + YGFloatIsUndefined(value) ? YGUnitUndefined : U, + }; + } +}; + template struct DimensionProp { template @@ -614,6 +624,17 @@ struct DimensionProp { } return WIN_STRUCT_REF(value); } + + template + static void set(YGNodeRef node, float newValue) { + YGValue value = Value::create(newValue); + if (((node->getStyle().*P)[idx].value != value.value && + value.unit != YGUnitUndefined) || + (node->getStyle().*P)[idx].unit != value.unit) { + (node->getStyle().*P)[idx] = value; + node->markDirtyAndPropogate(); + } + } }; } // namespace @@ -621,16 +642,8 @@ struct DimensionProp { #define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL( \ type, name, paramName, instanceName, dimension) \ void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \ - YGValue value = { \ - YGFloatSanitize(paramName), \ - YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \ - }; \ - if ((node->getStyle().instanceName[dimension].value != value.value && \ - value.unit != YGUnitUndefined) || \ - node->getStyle().instanceName[dimension].unit != value.unit) { \ - node->getStyle().instanceName[dimension] = value; \ - node->markDirtyAndPropogate(); \ - } \ + DimensionProp<&YGStyle::instanceName>::set( \ + node, paramName); \ } \ \ void YGNodeStyleSet##name##Percent( \ @@ -641,8 +654,8 @@ struct DimensionProp { }; \ if ((node->getStyle().instanceName[dimension].value != value.value && \ value.unit != YGUnitUndefined) || \ - node->getStyle().instanceName[dimension].unit != value.unit) { \ \ - node->getStyle().instanceName[dimension] = value; \ + node->getStyle().instanceName[dimension].unit != value.unit) { \ + node->getStyle().instanceName[dimension] = value; \ node->markDirtyAndPropogate(); \ } \ }