From be00354b7194bf182c9b66584f64c83e248d3007 Mon Sep 17 00:00:00 2001 From: Joe Vilches Date: Mon, 25 Nov 2024 00:40:03 -0800 Subject: [PATCH] Back out "Modify private apis to set, store, and get intrinsic sizing keywords" (#1750) Summary: X-link: https://github.com/facebook/react-native/pull/47895 Pull Request resolved: https://github.com/facebook/yoga/pull/1750 These APIs were only added so that we could do TDD as we work on intrinsic sizing functionality. As of right now they do nothing. We are aiming on publishing a new version of Yoga soon so for the time being we are going to back these out so as not to confuse anyone with this new functionality. Ideally we get to a point where we have some temporary experimental header to stage these in but this is a bit time sensitive so just backing out for now Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D66332307 fbshipit-source-id: 1d596964e0c893091c541988506e8b80fa6d1957 --- enums.py | 10 +- java/com/facebook/yoga/YogaUnit.java | 8 +- javascript/src/generated/YGEnums.ts | 6 -- tests/StyleValuePoolTest.cpp | 15 --- yoga/YGEnums.cpp | 6 -- yoga/YGEnums.h | 5 +- yoga/YGNodeStyle.cpp | 34 +++---- yoga/YGValue.h | 3 - yoga/algorithm/CalculateLayout.cpp | 2 +- yoga/enums/Unit.h | 5 +- yoga/node/Node.cpp | 12 +-- yoga/node/Node.h | 8 +- yoga/style/Style.h | 26 +++-- yoga/style/StyleLength.h | 21 ++-- yoga/style/StyleSizeLength.h | 139 --------------------------- yoga/style/StyleValueHandle.h | 8 -- yoga/style/StyleValuePool.h | 63 +----------- 17 files changed, 54 insertions(+), 317 deletions(-) delete mode 100644 yoga/style/StyleSizeLength.h diff --git a/enums.py b/enums.py index 5511f49d46..a81b8c882b 100755 --- a/enums.py +++ b/enums.py @@ -8,15 +8,7 @@ ENUMS = { "Direction": ["Inherit", "LTR", "RTL"], - "Unit": [ - "Undefined", - "Point", - "Percent", - "Auto", - "MaxContent", - "FitContent", - "Stretch", - ], + "Unit": ["Undefined", "Point", "Percent", "Auto"], "FlexDirection": ["Column", "ColumnReverse", "Row", "RowReverse"], "Justify": [ "FlexStart", diff --git a/java/com/facebook/yoga/YogaUnit.java b/java/com/facebook/yoga/YogaUnit.java index 5731a040d9..3614ec1059 100644 --- a/java/com/facebook/yoga/YogaUnit.java +++ b/java/com/facebook/yoga/YogaUnit.java @@ -13,10 +13,7 @@ public enum YogaUnit { UNDEFINED(0), POINT(1), PERCENT(2), - AUTO(3), - MAX_CONTENT(4), - FIT_CONTENT(5), - STRETCH(6); + AUTO(3); private final int mIntValue; @@ -34,9 +31,6 @@ public static YogaUnit fromInt(int value) { case 1: return POINT; case 2: return PERCENT; case 3: return AUTO; - case 4: return MAX_CONTENT; - case 5: return FIT_CONTENT; - case 6: return STRETCH; default: throw new IllegalArgumentException("Unknown enum value: " + value); } } diff --git a/javascript/src/generated/YGEnums.ts b/javascript/src/generated/YGEnums.ts index f389fe2fdf..2aafc682ff 100644 --- a/javascript/src/generated/YGEnums.ts +++ b/javascript/src/generated/YGEnums.ts @@ -125,9 +125,6 @@ export enum Unit { Point = 1, Percent = 2, Auto = 3, - MaxContent = 4, - FitContent = 5, - Stretch = 6, } export enum Wrap { @@ -206,9 +203,6 @@ const constants = { UNIT_POINT: Unit.Point, UNIT_PERCENT: Unit.Percent, UNIT_AUTO: Unit.Auto, - UNIT_MAX_CONTENT: Unit.MaxContent, - UNIT_FIT_CONTENT: Unit.FitContent, - UNIT_STRETCH: Unit.Stretch, WRAP_NO_WRAP: Wrap.NoWrap, WRAP_WRAP: Wrap.Wrap, WRAP_WRAP_REVERSE: Wrap.WrapReverse, diff --git a/tests/StyleValuePoolTest.cpp b/tests/StyleValuePoolTest.cpp index ff38acff36..0755059f35 100644 --- a/tests/StyleValuePoolTest.cpp +++ b/tests/StyleValuePoolTest.cpp @@ -128,19 +128,4 @@ TEST(StyleValuePool, store_undefined_after_large_int) { EXPECT_EQ(pool.getLength(handle), StyleLength::undefined()); } -TEST(StyleValuePool, store_keywords) { - StyleValuePool pool; - StyleValueHandle handleMaxContent; - StyleValueHandle handleFitContent; - StyleValueHandle handleStretch; - - pool.store(handleMaxContent, StyleSizeLength::ofMaxContent()); - pool.store(handleFitContent, StyleSizeLength::ofFitContent()); - pool.store(handleStretch, StyleSizeLength::ofStretch()); - - EXPECT_EQ(pool.getSize(handleMaxContent), StyleSizeLength::ofMaxContent()); - EXPECT_EQ(pool.getSize(handleFitContent), StyleSizeLength::ofFitContent()); - EXPECT_EQ(pool.getSize(handleStretch), StyleSizeLength::ofStretch()); -} - } // namespace facebook::yoga diff --git a/yoga/YGEnums.cpp b/yoga/YGEnums.cpp index 4bdace6b7a..cddd5d5849 100644 --- a/yoga/YGEnums.cpp +++ b/yoga/YGEnums.cpp @@ -245,12 +245,6 @@ const char* YGUnitToString(const YGUnit value) { return "percent"; case YGUnitAuto: return "auto"; - case YGUnitMaxContent: - return "max-content"; - case YGUnitFitContent: - return "fit-content"; - case YGUnitStretch: - return "stretch"; } return "unknown"; } diff --git a/yoga/YGEnums.h b/yoga/YGEnums.h index bb83bcfac9..27f0426f45 100644 --- a/yoga/YGEnums.h +++ b/yoga/YGEnums.h @@ -131,10 +131,7 @@ YG_ENUM_DECL( YGUnitUndefined, YGUnitPoint, YGUnitPercent, - YGUnitAuto, - YGUnitMaxContent, - YGUnitFitContent, - YGUnitStretch) + YGUnitAuto) YG_ENUM_DECL( YGWrap, diff --git a/yoga/YGNodeStyle.cpp b/yoga/YGNodeStyle.cpp index 1309117af4..8664b53ec8 100644 --- a/yoga/YGNodeStyle.cpp +++ b/yoga/YGNodeStyle.cpp @@ -177,19 +177,19 @@ float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) { void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) { updateStyle<&Style::flexBasis, &Style::setFlexBasis>( - node, StyleSizeLength::points(flexBasis)); + node, StyleLength::points(flexBasis)); } void YGNodeStyleSetFlexBasisPercent( const YGNodeRef node, const float flexBasisPercent) { updateStyle<&Style::flexBasis, &Style::setFlexBasis>( - node, StyleSizeLength::percent(flexBasisPercent)); + node, StyleLength::percent(flexBasisPercent)); } void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) { updateStyle<&Style::flexBasis, &Style::setFlexBasis>( - node, StyleSizeLength::ofAuto()); + node, StyleLength::ofAuto()); } YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { @@ -308,17 +308,17 @@ YGBoxSizing YGNodeStyleGetBoxSizing(const YGNodeConstRef node) { void YGNodeStyleSetWidth(YGNodeRef node, float points) { updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Width, StyleSizeLength::points(points)); + node, Dimension::Width, StyleLength::points(points)); } void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) { updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Width, StyleSizeLength::percent(percent)); + node, Dimension::Width, StyleLength::percent(percent)); } void YGNodeStyleSetWidthAuto(YGNodeRef node) { updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Width, StyleSizeLength::ofAuto()); + node, Dimension::Width, StyleLength::ofAuto()); } YGValue YGNodeStyleGetWidth(YGNodeConstRef node) { @@ -327,17 +327,17 @@ YGValue YGNodeStyleGetWidth(YGNodeConstRef node) { void YGNodeStyleSetHeight(YGNodeRef node, float points) { updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Height, StyleSizeLength::points(points)); + node, Dimension::Height, StyleLength::points(points)); } void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) { updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Height, StyleSizeLength::percent(percent)); + node, Dimension::Height, StyleLength::percent(percent)); } void YGNodeStyleSetHeightAuto(YGNodeRef node) { updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Height, StyleSizeLength::ofAuto()); + node, Dimension::Height, StyleLength::ofAuto()); } YGValue YGNodeStyleGetHeight(YGNodeConstRef node) { @@ -346,12 +346,12 @@ YGValue YGNodeStyleGetHeight(YGNodeConstRef node) { void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) { updateStyle<&Style::minDimension, &Style::setMinDimension>( - node, Dimension::Width, StyleSizeLength::points(minWidth)); + node, Dimension::Width, StyleLength::points(minWidth)); } void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) { updateStyle<&Style::minDimension, &Style::setMinDimension>( - node, Dimension::Width, StyleSizeLength::percent(minWidth)); + node, Dimension::Width, StyleLength::percent(minWidth)); } YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) { @@ -360,14 +360,14 @@ YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) { void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) { updateStyle<&Style::minDimension, &Style::setMinDimension>( - node, Dimension::Height, StyleSizeLength::points(minHeight)); + node, Dimension::Height, StyleLength::points(minHeight)); } void YGNodeStyleSetMinHeightPercent( const YGNodeRef node, const float minHeight) { updateStyle<&Style::minDimension, &Style::setMinDimension>( - node, Dimension::Height, StyleSizeLength::percent(minHeight)); + node, Dimension::Height, StyleLength::percent(minHeight)); } YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) { @@ -376,12 +376,12 @@ YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) { void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) { updateStyle<&Style::maxDimension, &Style::setMaxDimension>( - node, Dimension::Width, StyleSizeLength::points(maxWidth)); + node, Dimension::Width, StyleLength::points(maxWidth)); } void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) { updateStyle<&Style::maxDimension, &Style::setMaxDimension>( - node, Dimension::Width, StyleSizeLength::percent(maxWidth)); + node, Dimension::Width, StyleLength::percent(maxWidth)); } YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) { @@ -390,14 +390,14 @@ YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) { void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) { updateStyle<&Style::maxDimension, &Style::setMaxDimension>( - node, Dimension::Height, StyleSizeLength::points(maxHeight)); + node, Dimension::Height, StyleLength::points(maxHeight)); } void YGNodeStyleSetMaxHeightPercent( const YGNodeRef node, const float maxHeight) { updateStyle<&Style::maxDimension, &Style::setMaxDimension>( - node, Dimension::Height, StyleSizeLength::percent(maxHeight)); + node, Dimension::Height, StyleLength::percent(maxHeight)); } YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) { diff --git a/yoga/YGValue.h b/yoga/YGValue.h index 63c82f3da8..7fa6fd918e 100644 --- a/yoga/YGValue.h +++ b/yoga/YGValue.h @@ -65,9 +65,6 @@ inline bool operator==(const YGValue& lhs, const YGValue& rhs) { switch (lhs.unit) { case YGUnitUndefined: case YGUnitAuto: - case YGUnitFitContent: - case YGUnitMaxContent: - case YGUnitStretch: return true; case YGUnitPoint: case YGUnitPercent: diff --git a/yoga/algorithm/CalculateLayout.cpp b/yoga/algorithm/CalculateLayout.cpp index 8dc078afeb..a10b22151c 100644 --- a/yoga/algorithm/CalculateLayout.cpp +++ b/yoga/algorithm/CalculateLayout.cpp @@ -741,7 +741,7 @@ static float distributeFreeSpaceSecondPass( marginCross; const bool isLoosePercentageMeasurement = currentLineChild->getProcessedDimension(dimension(crossAxis)) - .isPercent() && + .unit() == Unit::Percent && sizingModeCrossDim != SizingMode::StretchFit; childCrossSizingMode = yoga::isUndefined(childCrossSize) || isLoosePercentageMeasurement diff --git a/yoga/enums/Unit.h b/yoga/enums/Unit.h index 685b1caece..57bd196970 100644 --- a/yoga/enums/Unit.h +++ b/yoga/enums/Unit.h @@ -20,14 +20,11 @@ enum class Unit : uint8_t { Point = YGUnitPoint, Percent = YGUnitPercent, Auto = YGUnitAuto, - MaxContent = YGUnitMaxContent, - FitContent = YGUnitFitContent, - Stretch = YGUnitStretch, }; template <> constexpr int32_t ordinalCount() { - return 7; + return 4; } constexpr Unit scopedEnum(YGUnit unscoped) { diff --git a/yoga/node/Node.cpp b/yoga/node/Node.cpp index e647a47b91..cf36ab09a4 100644 --- a/yoga/node/Node.cpp +++ b/yoga/node/Node.cpp @@ -314,16 +314,16 @@ void Node::setPosition( crossAxisTrailingEdge); } -Style::SizeLength Node::processFlexBasis() const { - Style::SizeLength flexBasis = style_.flexBasis(); - if (!flexBasis.isAuto() && !flexBasis.isUndefined()) { +Style::Length Node::processFlexBasis() const { + Style::Length flexBasis = style_.flexBasis(); + if (flexBasis.unit() != Unit::Auto && flexBasis.unit() != Unit::Undefined) { return flexBasis; } if (style_.flex().isDefined() && style_.flex().unwrap() > 0.0f) { - return config_->useWebDefaults() ? StyleSizeLength::ofAuto() - : StyleSizeLength::points(0); + return config_->useWebDefaults() ? StyleLength::ofAuto() + : StyleLength::points(0); } - return StyleSizeLength::ofAuto(); + return StyleLength::ofAuto(); } FloatOptional Node::resolveFlexBasis( diff --git a/yoga/node/Node.h b/yoga/node/Node.h index b3444c4118..d596c564cf 100644 --- a/yoga/node/Node.h +++ b/yoga/node/Node.h @@ -172,7 +172,7 @@ class YG_EXPORT Node : public ::YGNode { return isDirty_; } - Style::SizeLength getProcessedDimension(Dimension dimension) const { + Style::Length getProcessedDimension(Dimension dimension) const { return processedDimensions_[static_cast(dimension)]; } @@ -268,7 +268,7 @@ class YG_EXPORT Node : public ::YGNode { void setPosition(Direction direction, float ownerWidth, float ownerHeight); // Other methods - Style::SizeLength processFlexBasis() const; + Style::Length processFlexBasis() const; FloatOptional resolveFlexBasis( Direction direction, FlexDirection flexDirection, @@ -322,8 +322,8 @@ class YG_EXPORT Node : public ::YGNode { Node* owner_ = nullptr; std::vector children_; const Config* config_; - std::array processedDimensions_{ - {StyleSizeLength::undefined(), StyleSizeLength::undefined()}}; + std::array processedDimensions_{ + {StyleLength::undefined(), StyleLength::undefined()}}; }; inline Node* resolveRef(const YGNodeRef ref) { diff --git a/yoga/style/Style.h b/yoga/style/Style.h index 923b268bf8..73203e6cca 100644 --- a/yoga/style/Style.h +++ b/yoga/style/Style.h @@ -30,7 +30,6 @@ #include #include #include -#include #include namespace facebook::yoga { @@ -38,7 +37,6 @@ namespace facebook::yoga { class YG_EXPORT Style { public: using Length = StyleLength; - using SizeLength = StyleSizeLength; static constexpr float DefaultFlexGrow = 0.0f; static constexpr float DefaultFlexShrink = 0.0f; @@ -135,10 +133,10 @@ class YG_EXPORT Style { pool_.store(flexShrink_, value); } - Style::SizeLength flexBasis() const { - return pool_.getSize(flexBasis_); + Style::Length flexBasis() const { + return pool_.getLength(flexBasis_); } - void setFlexBasis(Style::SizeLength value) { + void setFlexBasis(Style::Length value) { pool_.store(flexBasis_, value); } @@ -177,17 +175,17 @@ class YG_EXPORT Style { pool_.store(gap_[yoga::to_underlying(gutter)], value); } - Style::SizeLength dimension(Dimension axis) const { - return pool_.getSize(dimensions_[yoga::to_underlying(axis)]); + Style::Length dimension(Dimension axis) const { + return pool_.getLength(dimensions_[yoga::to_underlying(axis)]); } - void setDimension(Dimension axis, Style::SizeLength value) { + void setDimension(Dimension axis, Style::Length value) { pool_.store(dimensions_[yoga::to_underlying(axis)], value); } - Style::SizeLength minDimension(Dimension axis) const { - return pool_.getSize(minDimensions_[yoga::to_underlying(axis)]); + Style::Length minDimension(Dimension axis) const { + return pool_.getLength(minDimensions_[yoga::to_underlying(axis)]); } - void setMinDimension(Dimension axis, Style::SizeLength value) { + void setMinDimension(Dimension axis, Style::Length value) { pool_.store(minDimensions_[yoga::to_underlying(axis)], value); } @@ -209,10 +207,10 @@ class YG_EXPORT Style { : FloatOptional{0.0}); } - Style::SizeLength maxDimension(Dimension axis) const { - return pool_.getSize(maxDimensions_[yoga::to_underlying(axis)]); + Style::Length maxDimension(Dimension axis) const { + return pool_.getLength(maxDimensions_[yoga::to_underlying(axis)]); } - void setMaxDimension(Dimension axis, Style::SizeLength value) { + void setMaxDimension(Dimension axis, Style::Length value) { pool_.store(maxDimensions_[yoga::to_underlying(axis)], value); } diff --git a/yoga/style/StyleLength.h b/yoga/style/StyleLength.h index 01e69718b2..7cc42d9eb5 100644 --- a/yoga/style/StyleLength.h +++ b/yoga/style/StyleLength.h @@ -19,11 +19,13 @@ namespace facebook::yoga { * 3. A CSS value: * a. value (e.g. 10px) * b. value of a reference + * 4. (soon) A math function which returns a value * * References: * 1. https://www.w3.org/TR/css-values-4/#lengths * 2. https://www.w3.org/TR/css-values-4/#percentage-value * 3. https://www.w3.org/TR/css-values-4/#mixed-percentages + * 4. https://www.w3.org/TR/css-values-4/#math */ class StyleLength { public: @@ -57,14 +59,6 @@ class StyleLength { return unit_ == Unit::Undefined; } - constexpr bool isPoints() const { - return unit_ == Unit::Point; - } - - constexpr bool isPercent() const { - return unit_ == Unit::Percent; - } - constexpr bool isDefined() const { return !isUndefined(); } @@ -73,6 +67,10 @@ class StyleLength { return value_; } + constexpr Unit unit() const { + return unit_; + } + constexpr FloatOptional resolve(float referenceLength) { switch (unit_) { case Unit::Point: @@ -92,11 +90,6 @@ class StyleLength { return value_ == rhs.value_ && unit_ == rhs.unit_; } - constexpr bool inexactEquals(const StyleLength& other) const { - return unit_ == other.unit_ && - facebook::yoga::inexactEquals(value_, other.value_); - } - private: // We intentionally do not allow direct construction using value and unit, to // avoid invalid, or redundant combinations. @@ -108,7 +101,7 @@ class StyleLength { }; inline bool inexactEquals(const StyleLength& a, const StyleLength& b) { - return a.inexactEquals(b); + return a.unit() == b.unit() && inexactEquals(a.value(), b.value()); } } // namespace facebook::yoga diff --git a/yoga/style/StyleSizeLength.h b/yoga/style/StyleSizeLength.h deleted file mode 100644 index 8dc4f24013..0000000000 --- a/yoga/style/StyleSizeLength.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include - -namespace facebook::yoga { - -/** - * This class represents a CSS Value for sizes (e.g. width, height, min-width, - * etc.). It may be one of: - * 1. Undefined - * 2. A keyword (e.g. auto, max-content, stretch, etc.) - * 3. A CSS value: - * a. value (e.g. 10px) - * b. value of a reference - * - * References: - * 1. https://www.w3.org/TR/css-values-4/#lengths - * 2. https://www.w3.org/TR/css-values-4/#percentage-value - * 3. https://www.w3.org/TR/css-values-4/#mixed-percentages - */ -class StyleSizeLength { - public: - constexpr StyleSizeLength() = default; - - constexpr static StyleSizeLength points(float value) { - return yoga::isUndefined(value) || yoga::isinf(value) - ? undefined() - : StyleSizeLength{FloatOptional{value}, Unit::Point}; - } - - constexpr static StyleSizeLength percent(float value) { - return yoga::isUndefined(value) || yoga::isinf(value) - ? undefined() - : StyleSizeLength{FloatOptional{value}, Unit::Percent}; - } - - constexpr static StyleSizeLength ofAuto() { - return StyleSizeLength{{}, Unit::Auto}; - } - - constexpr static StyleSizeLength ofMaxContent() { - return StyleSizeLength{{}, Unit::MaxContent}; - } - - constexpr static StyleSizeLength ofFitContent() { - return StyleSizeLength{{}, Unit::FitContent}; - } - - constexpr static StyleSizeLength ofStretch() { - return StyleSizeLength{{}, Unit::Stretch}; - } - - constexpr static StyleSizeLength undefined() { - return StyleSizeLength{{}, Unit::Undefined}; - } - - constexpr bool isAuto() const { - return unit_ == Unit::Auto; - } - - constexpr bool isMaxContent() const { - return unit_ == Unit::MaxContent; - } - - constexpr bool isFitContent() const { - return unit_ == Unit::FitContent; - } - - constexpr bool isStretch() const { - return unit_ == Unit::Stretch; - } - - constexpr bool isUndefined() const { - return unit_ == Unit::Undefined; - } - - constexpr bool isDefined() const { - return !isUndefined(); - } - - constexpr bool isPoints() const { - return unit_ == Unit::Point; - } - - constexpr bool isPercent() const { - return unit_ == Unit::Percent; - } - - constexpr FloatOptional value() const { - return value_; - } - - constexpr FloatOptional resolve(float referenceLength) { - switch (unit_) { - case Unit::Point: - return value_; - case Unit::Percent: - return FloatOptional{value_.unwrap() * referenceLength * 0.01f}; - default: - return FloatOptional{}; - } - } - - explicit constexpr operator YGValue() const { - return YGValue{value_.unwrap(), unscopedEnum(unit_)}; - } - - constexpr bool operator==(const StyleSizeLength& rhs) const { - return value_ == rhs.value_ && unit_ == rhs.unit_; - } - - constexpr bool inexactEquals(const StyleSizeLength& other) const { - return unit_ == other.unit_ && - facebook::yoga::inexactEquals(value_, other.value_); - } - - private: - // We intentionally do not allow direct construction using value and unit, to - // avoid invalid, or redundant combinations. - constexpr StyleSizeLength(FloatOptional value, Unit unit) - : value_(value), unit_(unit) {} - - FloatOptional value_{}; - Unit unit_{Unit::Undefined}; -}; - -inline bool inexactEquals(const StyleSizeLength& a, const StyleSizeLength& b) { - return a.inexactEquals(b); -} - -} // namespace facebook::yoga diff --git a/yoga/style/StyleValueHandle.h b/yoga/style/StyleValueHandle.h index d9c6ae0579..f4b97f0a9f 100644 --- a/yoga/style/StyleValueHandle.h +++ b/yoga/style/StyleValueHandle.h @@ -62,16 +62,8 @@ class StyleValueHandle { Percent, Number, Auto, - Keyword }; - // Intentionally leaving out auto as a fast path - enum class Keyword : uint8_t { MaxContent, FitContent, Stretch }; - - constexpr bool isKeyword(Keyword keyword) const { - return type() == Type::Keyword && value() == static_cast(keyword); - } - constexpr Type type() const { return static_cast(repr_ & kHandleTypeMask); } diff --git a/yoga/style/StyleValuePool.h b/yoga/style/StyleValuePool.h index dfee30ade9..597eae4c43 100644 --- a/yoga/style/StyleValuePool.h +++ b/yoga/style/StyleValuePool.h @@ -13,7 +13,6 @@ #include #include #include -#include #include namespace facebook::yoga { @@ -33,30 +32,13 @@ class StyleValuePool { } else if (length.isAuto()) { handle.setType(StyleValueHandle::Type::Auto); } else { - auto type = length.isPoints() ? StyleValueHandle::Type::Point - : StyleValueHandle::Type::Percent; + auto type = length.unit() == Unit::Point + ? StyleValueHandle::Type::Point + : StyleValueHandle::Type::Percent; storeValue(handle, length.value().unwrap(), type); } } - void store(StyleValueHandle& handle, StyleSizeLength sizeValue) { - if (sizeValue.isUndefined()) { - handle.setType(StyleValueHandle::Type::Undefined); - } else if (sizeValue.isAuto()) { - handle.setType(StyleValueHandle::Type::Auto); - } else if (sizeValue.isMaxContent()) { - storeKeyword(handle, StyleValueHandle::Keyword::MaxContent); - } else if (sizeValue.isStretch()) { - storeKeyword(handle, StyleValueHandle::Keyword::Stretch); - } else if (sizeValue.isFitContent()) { - storeKeyword(handle, StyleValueHandle::Keyword::FitContent); - } else { - auto type = sizeValue.isPoints() ? StyleValueHandle::Type::Point - : StyleValueHandle::Type::Percent; - storeValue(handle, sizeValue.value().unwrap(), type); - } - } - void store(StyleValueHandle& handle, FloatOptional number) { if (number.isUndefined()) { handle.setType(StyleValueHandle::Type::Undefined); @@ -84,31 +66,6 @@ class StyleValuePool { } } - StyleSizeLength getSize(StyleValueHandle handle) const { - if (handle.isUndefined()) { - return StyleSizeLength::undefined(); - } else if (handle.isAuto()) { - return StyleSizeLength::ofAuto(); - } else if (handle.isKeyword(StyleValueHandle::Keyword::MaxContent)) { - return StyleSizeLength::ofMaxContent(); - } else if (handle.isKeyword(StyleValueHandle::Keyword::FitContent)) { - return StyleSizeLength::ofFitContent(); - } else if (handle.isKeyword(StyleValueHandle::Keyword::Stretch)) { - return StyleSizeLength::ofStretch(); - } else { - assert( - handle.type() == StyleValueHandle::Type::Point || - handle.type() == StyleValueHandle::Type::Percent); - float value = (handle.isValueIndexed()) - ? std::bit_cast(buffer_.get32(handle.value())) - : unpackInlineInteger(handle.value()); - - return handle.type() == StyleValueHandle::Type::Point - ? StyleSizeLength::points(value) - : StyleSizeLength::percent(value); - } - } - FloatOptional getNumber(StyleValueHandle handle) const { if (handle.isUndefined()) { return FloatOptional{}; @@ -141,20 +98,6 @@ class StyleValuePool { } } - void storeKeyword( - StyleValueHandle& handle, - StyleValueHandle::Keyword keyword) { - handle.setType(StyleValueHandle::Type::Keyword); - - if (handle.isValueIndexed()) { - auto newIndex = - buffer_.replace(handle.value(), static_cast(keyword)); - handle.setValue(newIndex); - } else { - handle.setValue(static_cast(keyword)); - } - } - static constexpr bool isIntegerPackable(float f) { constexpr uint16_t kMaxInlineAbsValue = (1 << 11) - 1;