From 2437d26ca56e94df8fcede27863ee4004f84c4ae Mon Sep 17 00:00:00 2001 From: Joe Vilches Date: Wed, 9 Oct 2024 19:20:15 -0700 Subject: [PATCH] Sunset the `value` namespace (#1720) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1720 X-link: https://github.com/facebook/react-native/pull/46930 This is not really needed anymore, we can just use `StyleLength` statics instead Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D63922280 fbshipit-source-id: cd953bae8e9f68574463eafc49c33c2e85ac1856 --- tests/StyleTest.cpp | 8 ++--- tests/StyleValuePoolTest.cpp | 48 +++++++++++++++--------------- yoga/YGNodeStyle.cpp | 57 ++++++++++++++++++------------------ yoga/node/Node.cpp | 5 ++-- yoga/node/Node.h | 2 +- yoga/style/StyleLength.h | 32 -------------------- yoga/style/StyleValuePool.h | 8 ++--- 7 files changed, 65 insertions(+), 95 deletions(-) diff --git a/tests/StyleTest.cpp b/tests/StyleTest.cpp index 4832aeaead..d44b73d50f 100644 --- a/tests/StyleTest.cpp +++ b/tests/StyleTest.cpp @@ -12,7 +12,7 @@ namespace facebook::yoga { TEST(Style, computed_padding_is_floored) { yoga::Style style; - style.setPadding(Edge::All, value::points(-1.0f)); + style.setPadding(Edge::All, StyleLength::points(-1.0f)); auto paddingStart = style.computeInlineStartPadding( FlexDirection::Row, Direction::LTR, 0.0f /*widthSize*/); ASSERT_EQ(paddingStart, 0.0f); @@ -20,7 +20,7 @@ TEST(Style, computed_padding_is_floored) { TEST(Style, computed_border_is_floored) { yoga::Style style; - style.setBorder(Edge::All, value::points(-1.0f)); + style.setBorder(Edge::All, StyleLength::points(-1.0f)); auto borderStart = style.computeInlineStartBorder(FlexDirection::Row, Direction::LTR); ASSERT_EQ(borderStart, 0.0f); @@ -28,14 +28,14 @@ TEST(Style, computed_border_is_floored) { TEST(Style, computed_gap_is_floored) { yoga::Style style; - style.setGap(Gutter::Column, value::points(-1.0f)); + style.setGap(Gutter::Column, StyleLength::points(-1.0f)); auto gapBetweenColumns = style.computeGapForAxis(FlexDirection::Row, 0.0); ASSERT_EQ(gapBetweenColumns, 0.0f); } TEST(Style, computed_margin_is_not_floored) { yoga::Style style; - style.setMargin(Edge::All, value::points(-1.0f)); + style.setMargin(Edge::All, StyleLength::points(-1.0f)); auto marginStart = style.computeInlineStartMargin( FlexDirection::Row, Direction::LTR, 0.0f /*widthSize*/); ASSERT_EQ(marginStart, -1.0f); diff --git a/tests/StyleValuePoolTest.cpp b/tests/StyleValuePoolTest.cpp index 10ba04d3da..0755059f35 100644 --- a/tests/StyleValuePoolTest.cpp +++ b/tests/StyleValuePoolTest.cpp @@ -16,7 +16,7 @@ TEST(StyleValuePool, undefined_at_init) { EXPECT_TRUE(handle.isUndefined()); EXPECT_FALSE(handle.isDefined()); - EXPECT_EQ(pool.getLength(handle), value::undefined()); + EXPECT_EQ(pool.getLength(handle), StyleLength::undefined()); EXPECT_EQ(pool.getNumber(handle), FloatOptional{}); } @@ -25,63 +25,63 @@ TEST(StyleValuePool, auto_at_init) { auto handle = StyleValueHandle::ofAuto(); EXPECT_TRUE(handle.isAuto()); - EXPECT_EQ(pool.getLength(handle), value::ofAuto()); + EXPECT_EQ(pool.getLength(handle), StyleLength::ofAuto()); } TEST(StyleValuePool, store_small_int_points) { StyleValuePool pool; StyleValueHandle handle; - pool.store(handle, value::points(10)); + pool.store(handle, StyleLength::points(10)); - EXPECT_EQ(pool.getLength(handle), value::points(10)); + EXPECT_EQ(pool.getLength(handle), StyleLength::points(10)); } TEST(StyleValuePool, store_small_negative_int_points) { StyleValuePool pool; StyleValueHandle handle; - pool.store(handle, value::points(-10)); + pool.store(handle, StyleLength::points(-10)); - EXPECT_EQ(pool.getLength(handle), value::points(-10)); + EXPECT_EQ(pool.getLength(handle), StyleLength::points(-10)); } TEST(StyleValuePool, store_small_int_percent) { StyleValuePool pool; StyleValueHandle handle; - pool.store(handle, value::percent(10)); + pool.store(handle, StyleLength::percent(10)); - EXPECT_EQ(pool.getLength(handle), value::percent(10)); + EXPECT_EQ(pool.getLength(handle), StyleLength::percent(10)); } TEST(StyleValuePool, store_large_int_percent) { StyleValuePool pool; StyleValueHandle handle; - pool.store(handle, value::percent(262144)); + pool.store(handle, StyleLength::percent(262144)); - EXPECT_EQ(pool.getLength(handle), value::percent(262144)); + EXPECT_EQ(pool.getLength(handle), StyleLength::percent(262144)); } TEST(StyleValuePool, store_large_int_after_small_int) { StyleValuePool pool; StyleValueHandle handle; - pool.store(handle, value::percent(10)); - pool.store(handle, value::percent(262144)); + pool.store(handle, StyleLength::percent(10)); + pool.store(handle, StyleLength::percent(262144)); - EXPECT_EQ(pool.getLength(handle), value::percent(262144)); + EXPECT_EQ(pool.getLength(handle), StyleLength::percent(262144)); } TEST(StyleValuePool, store_small_int_after_large_int) { StyleValuePool pool; StyleValueHandle handle; - pool.store(handle, value::percent(262144)); - pool.store(handle, value::percent(10)); + pool.store(handle, StyleLength::percent(262144)); + pool.store(handle, StyleLength::percent(10)); - EXPECT_EQ(pool.getLength(handle), value::percent(10)); + EXPECT_EQ(pool.getLength(handle), StyleLength::percent(10)); } TEST(StyleValuePool, store_small_int_number) { @@ -97,35 +97,35 @@ TEST(StyleValuePool, store_undefined) { StyleValuePool pool; StyleValueHandle handle; - pool.store(handle, value::undefined()); + pool.store(handle, StyleLength::undefined()); EXPECT_TRUE(handle.isUndefined()); EXPECT_FALSE(handle.isDefined()); - EXPECT_EQ(pool.getLength(handle), value::undefined()); + EXPECT_EQ(pool.getLength(handle), StyleLength::undefined()); } TEST(StyleValuePool, store_undefined_after_small_int) { StyleValuePool pool; StyleValueHandle handle; - pool.store(handle, value::points(10)); - pool.store(handle, value::undefined()); + pool.store(handle, StyleLength::points(10)); + pool.store(handle, StyleLength::undefined()); EXPECT_TRUE(handle.isUndefined()); EXPECT_FALSE(handle.isDefined()); - EXPECT_EQ(pool.getLength(handle), value::undefined()); + EXPECT_EQ(pool.getLength(handle), StyleLength::undefined()); } TEST(StyleValuePool, store_undefined_after_large_int) { StyleValuePool pool; StyleValueHandle handle; - pool.store(handle, value::points(262144)); - pool.store(handle, value::undefined()); + pool.store(handle, StyleLength::points(262144)); + pool.store(handle, StyleLength::undefined()); EXPECT_TRUE(handle.isUndefined()); EXPECT_FALSE(handle.isDefined()); - EXPECT_EQ(pool.getLength(handle), value::undefined()); + EXPECT_EQ(pool.getLength(handle), StyleLength::undefined()); } } // namespace facebook::yoga diff --git a/yoga/YGNodeStyle.cpp b/yoga/YGNodeStyle.cpp index d2a10b0591..8664b53ec8 100644 --- a/yoga/YGNodeStyle.cpp +++ b/yoga/YGNodeStyle.cpp @@ -177,18 +177,19 @@ float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) { void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) { updateStyle<&Style::flexBasis, &Style::setFlexBasis>( - node, value::points(flexBasis)); + node, StyleLength::points(flexBasis)); } void YGNodeStyleSetFlexBasisPercent( const YGNodeRef node, const float flexBasisPercent) { updateStyle<&Style::flexBasis, &Style::setFlexBasis>( - node, value::percent(flexBasisPercent)); + node, StyleLength::percent(flexBasisPercent)); } void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) { - updateStyle<&Style::flexBasis, &Style::setFlexBasis>(node, value::ofAuto()); + updateStyle<&Style::flexBasis, &Style::setFlexBasis>( + node, StyleLength::ofAuto()); } YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { @@ -197,17 +198,17 @@ YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float points) { updateStyle<&Style::position, &Style::setPosition>( - node, scopedEnum(edge), value::points(points)); + node, scopedEnum(edge), StyleLength::points(points)); } void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float percent) { updateStyle<&Style::position, &Style::setPosition>( - node, scopedEnum(edge), value::percent(percent)); + node, scopedEnum(edge), StyleLength::percent(percent)); } void YGNodeStyleSetPositionAuto(YGNodeRef node, YGEdge edge) { updateStyle<&Style::position, &Style::setPosition>( - node, scopedEnum(edge), value::ofAuto()); + node, scopedEnum(edge), StyleLength::ofAuto()); } YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) { @@ -216,17 +217,17 @@ YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) { void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float points) { updateStyle<&Style::margin, &Style::setMargin>( - node, scopedEnum(edge), value::points(points)); + node, scopedEnum(edge), StyleLength::points(points)); } void YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge, float percent) { updateStyle<&Style::margin, &Style::setMargin>( - node, scopedEnum(edge), value::percent(percent)); + node, scopedEnum(edge), StyleLength::percent(percent)); } void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) { updateStyle<&Style::margin, &Style::setMargin>( - node, scopedEnum(edge), value::ofAuto()); + node, scopedEnum(edge), StyleLength::ofAuto()); } YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) { @@ -235,12 +236,12 @@ YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) { void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float points) { updateStyle<&Style::padding, &Style::setPadding>( - node, scopedEnum(edge), value::points(points)); + node, scopedEnum(edge), StyleLength::points(points)); } void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float percent) { updateStyle<&Style::padding, &Style::setPadding>( - node, scopedEnum(edge), value::percent(percent)); + node, scopedEnum(edge), StyleLength::percent(percent)); } YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) { @@ -252,7 +253,7 @@ void YGNodeStyleSetBorder( const YGEdge edge, const float border) { updateStyle<&Style::border, &Style::setBorder>( - node, scopedEnum(edge), value::points(border)); + node, scopedEnum(edge), StyleLength::points(border)); } float YGNodeStyleGetBorder(const YGNodeConstRef node, const YGEdge edge) { @@ -269,12 +270,12 @@ void YGNodeStyleSetGap( const YGGutter gutter, const float gapLength) { updateStyle<&Style::gap, &Style::setGap>( - node, scopedEnum(gutter), value::points(gapLength)); + node, scopedEnum(gutter), StyleLength::points(gapLength)); } void YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float percent) { updateStyle<&Style::gap, &Style::setGap>( - node, scopedEnum(gutter), value::percent(percent)); + node, scopedEnum(gutter), StyleLength::percent(percent)); } float YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) { @@ -307,17 +308,17 @@ YGBoxSizing YGNodeStyleGetBoxSizing(const YGNodeConstRef node) { void YGNodeStyleSetWidth(YGNodeRef node, float points) { updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Width, value::points(points)); + node, Dimension::Width, StyleLength::points(points)); } void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) { updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Width, value::percent(percent)); + node, Dimension::Width, StyleLength::percent(percent)); } void YGNodeStyleSetWidthAuto(YGNodeRef node) { updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Width, value::ofAuto()); + node, Dimension::Width, StyleLength::ofAuto()); } YGValue YGNodeStyleGetWidth(YGNodeConstRef node) { @@ -326,17 +327,17 @@ YGValue YGNodeStyleGetWidth(YGNodeConstRef node) { void YGNodeStyleSetHeight(YGNodeRef node, float points) { updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Height, value::points(points)); + node, Dimension::Height, StyleLength::points(points)); } void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) { updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Height, value::percent(percent)); + node, Dimension::Height, StyleLength::percent(percent)); } void YGNodeStyleSetHeightAuto(YGNodeRef node) { updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Height, value::ofAuto()); + node, Dimension::Height, StyleLength::ofAuto()); } YGValue YGNodeStyleGetHeight(YGNodeConstRef node) { @@ -345,12 +346,12 @@ YGValue YGNodeStyleGetHeight(YGNodeConstRef node) { void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) { updateStyle<&Style::minDimension, &Style::setMinDimension>( - node, Dimension::Width, value::points(minWidth)); + node, Dimension::Width, StyleLength::points(minWidth)); } void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) { updateStyle<&Style::minDimension, &Style::setMinDimension>( - node, Dimension::Width, value::percent(minWidth)); + node, Dimension::Width, StyleLength::percent(minWidth)); } YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) { @@ -359,14 +360,14 @@ YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) { void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) { updateStyle<&Style::minDimension, &Style::setMinDimension>( - node, Dimension::Height, value::points(minHeight)); + node, Dimension::Height, StyleLength::points(minHeight)); } void YGNodeStyleSetMinHeightPercent( const YGNodeRef node, const float minHeight) { updateStyle<&Style::minDimension, &Style::setMinDimension>( - node, Dimension::Height, value::percent(minHeight)); + node, Dimension::Height, StyleLength::percent(minHeight)); } YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) { @@ -375,12 +376,12 @@ YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) { void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) { updateStyle<&Style::maxDimension, &Style::setMaxDimension>( - node, Dimension::Width, value::points(maxWidth)); + node, Dimension::Width, StyleLength::points(maxWidth)); } void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) { updateStyle<&Style::maxDimension, &Style::setMaxDimension>( - node, Dimension::Width, value::percent(maxWidth)); + node, Dimension::Width, StyleLength::percent(maxWidth)); } YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) { @@ -389,14 +390,14 @@ YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) { void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) { updateStyle<&Style::maxDimension, &Style::setMaxDimension>( - node, Dimension::Height, value::points(maxHeight)); + node, Dimension::Height, StyleLength::points(maxHeight)); } void YGNodeStyleSetMaxHeightPercent( const YGNodeRef node, const float maxHeight) { updateStyle<&Style::maxDimension, &Style::setMaxDimension>( - node, Dimension::Height, value::percent(maxHeight)); + node, Dimension::Height, StyleLength::percent(maxHeight)); } YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) { diff --git a/yoga/node/Node.cpp b/yoga/node/Node.cpp index 3189f3bbef..7c6bea55e3 100644 --- a/yoga/node/Node.cpp +++ b/yoga/node/Node.cpp @@ -288,9 +288,10 @@ Style::Length Node::processFlexBasis() const { return flexBasis; } if (style_.flex().isDefined() && style_.flex().unwrap() > 0.0f) { - return config_->useWebDefaults() ? value::ofAuto() : value::points(0); + return config_->useWebDefaults() ? StyleLength::ofAuto() + : StyleLength::points(0); } - return value::ofAuto(); + return StyleLength::ofAuto(); } FloatOptional Node::resolveFlexBasis( diff --git a/yoga/node/Node.h b/yoga/node/Node.h index 5f38ac1350..34ef6d955e 100644 --- a/yoga/node/Node.h +++ b/yoga/node/Node.h @@ -302,7 +302,7 @@ class YG_EXPORT Node : public ::YGNode { std::vector children_; const Config* config_; std::array processedDimensions_{ - {value::undefined(), value::undefined()}}; + {StyleLength::undefined(), StyleLength::undefined()}}; }; inline Node* resolveRef(const YGNodeRef ref) { diff --git a/yoga/style/StyleLength.h b/yoga/style/StyleLength.h index 242698abf4..7cc42d9eb5 100644 --- a/yoga/style/StyleLength.h +++ b/yoga/style/StyleLength.h @@ -104,36 +104,4 @@ inline bool inexactEquals(const StyleLength& a, const StyleLength& b) { return a.unit() == b.unit() && inexactEquals(a.value(), b.value()); } -namespace value { - -/** - * Canonical unit (one YGUnitPoint) - */ -constexpr StyleLength points(float value) { - return StyleLength::points(value); -} - -/** - * Percent of reference - */ -constexpr StyleLength percent(float value) { - return StyleLength::percent(value); -} - -/** - * "auto" keyword - */ -constexpr StyleLength ofAuto() { - return StyleLength::ofAuto(); -} - -/** - * Undefined - */ -constexpr StyleLength undefined() { - return StyleLength::undefined(); -} - -} // namespace value - } // namespace facebook::yoga diff --git a/yoga/style/StyleValuePool.h b/yoga/style/StyleValuePool.h index 3b17725444..597eae4c43 100644 --- a/yoga/style/StyleValuePool.h +++ b/yoga/style/StyleValuePool.h @@ -49,9 +49,9 @@ class StyleValuePool { StyleLength getLength(StyleValueHandle handle) const { if (handle.isUndefined()) { - return value::undefined(); + return StyleLength::undefined(); } else if (handle.isAuto()) { - return value::ofAuto(); + return StyleLength::ofAuto(); } else { assert( handle.type() == StyleValueHandle::Type::Point || @@ -61,8 +61,8 @@ class StyleValuePool { : unpackInlineInteger(handle.value()); return handle.type() == StyleValueHandle::Type::Point - ? value::points(value) - : value::percent(value); + ? StyleLength::points(value) + : StyleLength::percent(value); } }