From 05d205cf89285a534e326830ad44de768e4e62b0 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Wed, 1 May 2019 06:47:31 -0700 Subject: [PATCH] Deduplicate `updateStyle` overloads Summary: @public The extra overload of `updateStyle` introduced in D15078961 can also handle `BitfieldRef`. That means that we can remove the more specific implementation previously introduced for `BitfieldRef` Reviewed By: SidharthGuglani Differential Revision: D15081069 fbshipit-source-id: 98f1f3478627974c5273c85d268ca07350f303d7 --- yoga/Yoga.cpp | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 745188a4..6a394971 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -549,15 +549,6 @@ void updateStyle( } } -template (YGStyle::*Prop)()> -void updateStyle(YGNode* node, T value) { - updateStyle( - node, - value, - [](YGStyle& s, T x) { return (s.*Prop)() != x; }, - [](YGStyle& s, T x) { (s.*Prop)() = x; }); -} - template void updateStyle(YGNode* node, Ref (YGStyle::*prop)(), T value) { updateStyle( @@ -583,8 +574,15 @@ void updateIndexedStyleProp( } // namespace +// MSVC has trouble inferring the return type of pointer to member functions +// with const and non-const overloads, instead of preferring the non-const +// overload like clang and GCC. For the purposes of updateStyle(), we can help +// MSVC by specifying that return type explicitely. In combination with +// decltype, MSVC will prefer the non-const version. +#define MSVC_HINT(PROP) decltype(YGStyle{}.PROP()) + void YGNodeStyleSetDirection(const YGNodeRef node, const YGDirection value) { - updateStyle(node, value); + updateStyle(node, &YGStyle::direction, value); } YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) { return node->getStyle().direction(); @@ -593,7 +591,8 @@ YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) { void YGNodeStyleSetFlexDirection( const YGNodeRef node, const YGFlexDirection flexDirection) { - updateStyle(node, flexDirection); + updateStyle( + node, &YGStyle::flexDirection, flexDirection); } YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeConstRef node) { return node->getStyle().flexDirection(); @@ -602,7 +601,8 @@ YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeConstRef node) { void YGNodeStyleSetJustifyContent( const YGNodeRef node, const YGJustify justifyContent) { - updateStyle(node, justifyContent); + updateStyle( + node, &YGStyle::justifyContent, justifyContent); } YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) { return node->getStyle().justifyContent(); @@ -611,21 +611,22 @@ YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) { void YGNodeStyleSetAlignContent( const YGNodeRef node, const YGAlign alignContent) { - updateStyle(node, alignContent); + updateStyle( + node, &YGStyle::alignContent, alignContent); } YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) { return node->getStyle().alignContent(); } void YGNodeStyleSetAlignItems(const YGNodeRef node, const YGAlign alignItems) { - updateStyle(node, alignItems); + updateStyle(node, &YGStyle::alignItems, alignItems); } YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) { return node->getStyle().alignItems(); } void YGNodeStyleSetAlignSelf(const YGNodeRef node, const YGAlign alignSelf) { - updateStyle(node, alignSelf); + updateStyle(node, &YGStyle::alignSelf, alignSelf); } YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) { return node->getStyle().alignSelf(); @@ -634,40 +635,34 @@ YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) { void YGNodeStyleSetPositionType( const YGNodeRef node, const YGPositionType positionType) { - updateStyle(node, positionType); + updateStyle( + node, &YGStyle::positionType, positionType); } YGPositionType YGNodeStyleGetPositionType(const YGNodeConstRef node) { return node->getStyle().positionType(); } void YGNodeStyleSetFlexWrap(const YGNodeRef node, const YGWrap flexWrap) { - updateStyle(node, flexWrap); + updateStyle(node, &YGStyle::flexWrap, flexWrap); } YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) { return node->getStyle().flexWrap(); } void YGNodeStyleSetOverflow(const YGNodeRef node, const YGOverflow overflow) { - updateStyle(node, overflow); + updateStyle(node, &YGStyle::overflow, overflow); } YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) { return node->getStyle().overflow(); } void YGNodeStyleSetDisplay(const YGNodeRef node, const YGDisplay display) { - updateStyle(node, display); + updateStyle(node, &YGStyle::display, display); } YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) { return node->getStyle().display(); } -// MSVC has trouble inferring the return type of pointer to member functions -// with const and non-const overloads, instead of preferring the non-const -// overload like clang and GCC. For the purposes of updateStyle(), we can help -// MSVC by specifying that return type explicitely. In combination with -// decltype, MSVC will prefer the non-const version. -#define MSVC_HINT(PROP) decltype(YGStyle{}.PROP()) - // TODO(T26792433): Change the API to accept YGFloatOptional. void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { updateStyle(node, &YGStyle::flex, YGFloatOptional{flex});