From f33a623c9272eea7161d840ec7b84dc6a6919d8d Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Wed, 7 Aug 2019 16:17:00 -0700 Subject: [PATCH] Remove style property bitmask Summary: @public Removes the style properties bitmask. We have used this for experimentation, and it's no longer necessary. This simplifyies the code, and allows us to cut over to `Bitfield.h` more easily. Reviewed By: astreet Differential Revision: D16648862 fbshipit-source-id: 17c0899807af976f4ba34db54f8f0f6a3cd92519 --- ReactCommon/yoga/yoga/YGStyle.h | 112 ++++++-------------------------- 1 file changed, 20 insertions(+), 92 deletions(-) diff --git a/ReactCommon/yoga/yoga/YGStyle.h b/ReactCommon/yoga/yoga/YGStyle.h index ce3816040af..22196556721 100644 --- a/ReactCommon/yoga/yoga/YGStyle.h +++ b/ReactCommon/yoga/yoga/YGStyle.h @@ -7,7 +7,6 @@ #pragma once #include #include -#include #include #include #include "CompactValue.h" @@ -26,12 +25,8 @@ decltype(FIELD##_) get_##FIELD() const { return FIELD##_; } \ void set_##FIELD(decltype(FIELD##_) x) { FIELD##_ = x; } -#define BITFIELD_REF(FIELD) \ - BitfieldRef< \ - decltype(FIELD##_), \ - &YGStyle::get_##FIELD, \ - &YGStyle::set_##FIELD, \ - FIELD##Bit> +#define BITFIELD_REF(FIELD) \ + BitfieldRef class YGStyle { template @@ -39,28 +34,21 @@ class YGStyle { facebook::yoga::detail::Values()>; using CompactValue = facebook::yoga::detail::CompactValue; - static constexpr uint64_t allBits(int fromBit, int toBit) { - return fromBit < toBit - ? (uint64_t{1} << fromBit) | allBits(fromBit + 1, toBit) - : 0; - } - public: using Dimensions = Values; using Edges = Values; - template + template struct Ref { YGStyle& style; operator T() const { return style.*Prop; } - Ref& operator=(T value) { + Ref& operator=(T value) { style.*Prop = value; - style.assignedProps_.set(PropBit); return *this; } }; - template YGStyle::*Prop, int PropBit> + template YGStyle::*Prop> struct IdxRef { struct Ref { YGStyle& style; @@ -69,16 +57,13 @@ public: operator YGValue() const { return (style.*Prop)[idx]; } Ref& operator=(CompactValue value) { (style.*Prop)[idx] = value; - style.assignedProps_.set(PropBit + idx); return *this; } }; YGStyle& style; - IdxRef& operator=(const Values& values) { + IdxRef& operator=(const Values& values) { style.*Prop = values; - style.assignedProps_ |= - allBits(PropBit, PropBit + facebook::yoga::enums::count()); return *this; } operator const Values&() const { return style.*Prop; } @@ -86,18 +71,13 @@ public: CompactValue operator[](Idx idx) const { return (style.*Prop)[idx]; } }; - template < - typename T, - T (YGStyle::*Get)() const, - void (YGStyle::*Set)(T), - int PropBit> + template struct BitfieldRef { YGStyle& style; operator T() const { return (style.*Get)(); } - BitfieldRef& operator=(T x) { + BitfieldRef& operator=(T x) { (style.*Set)(x); - style.assignedProps_.set(PropBit); return *this; } }; @@ -125,41 +105,7 @@ public: ~YGStyle() = default; - static constexpr int directionBit = 0; - static constexpr int flexDirectionBit = directionBit + 1; - static constexpr int justifyContentBit = flexDirectionBit + 1; - static constexpr int alignContentBit = justifyContentBit + 1; - static constexpr int alignItemsBit = alignContentBit + 1; - static constexpr int alignSelfBit = alignItemsBit + 1; - static constexpr int positionTypeBit = alignSelfBit + 1; - static constexpr int flexWrapBit = positionTypeBit + 1; - static constexpr int overflowBit = flexWrapBit + 1; - static constexpr int displayBit = overflowBit + 1; - static constexpr int flexBit = displayBit + 1; - static constexpr int flexGrowBit = flexBit + 1; - static constexpr int flexShrinkBit = flexGrowBit + 1; - static constexpr int flexBasisBit = flexShrinkBit + 1; - static constexpr int marginBit = flexBasisBit + 1; - static constexpr int positionBit = - marginBit + facebook::yoga::enums::count(); - static constexpr int paddingBit = - positionBit + facebook::yoga::enums::count(); - static constexpr int borderBit = - paddingBit + facebook::yoga::enums::count(); - static constexpr int dimensionsBit = - borderBit + facebook::yoga::enums::count(); - static constexpr int maxDimensionsBit = - dimensionsBit + facebook::yoga::enums::count(); - static constexpr int minDimensionsBit = - maxDimensionsBit + facebook::yoga::enums::count(); - static constexpr int aspectRatioBit = - minDimensionsBit + facebook::yoga::enums::count(); - - static constexpr int numStyles = aspectRatioBit + 1; - private: - std::bitset assignedProps_; - /* Some platforms don't support enum bitfields, so please use BITFIELD_ENUM_SIZED(BITS_COUNT) */ YGDirection direction_ BITFIELD_ENUM_SIZED(2); @@ -198,10 +144,6 @@ private: BITFIELD_ACCESSORS(display); public: - const decltype(assignedProps_)& assignedProps() const { - return assignedProps_; - } - // for library users needing a type using ValueRepr = std::remove_reference::type; @@ -236,59 +178,45 @@ public: BITFIELD_REF(display) display() { return {*this}; } YGFloatOptional flex() const { return flex_; } - Ref flex() { return {*this}; } + Ref flex() { return {*this}; } YGFloatOptional flexGrow() const { return flexGrow_; } - Ref flexGrow() { - return {*this}; - } + Ref flexGrow() { return {*this}; } YGFloatOptional flexShrink() const { return flexShrink_; } - Ref flexShrink() { - return {*this}; - } + Ref flexShrink() { return {*this}; } CompactValue flexBasis() const { return flexBasis_; } - Ref flexBasis() { - return {*this}; - } + Ref flexBasis() { return {*this}; } const Edges& margin() const { return margin_; } - IdxRef margin() { return {*this}; } + IdxRef margin() { return {*this}; } const Edges& position() const { return position_; } - IdxRef position() { - return {*this}; - } + IdxRef position() { return {*this}; } const Edges& padding() const { return padding_; } - IdxRef padding() { return {*this}; } + IdxRef padding() { return {*this}; } const Edges& border() const { return border_; } - IdxRef border() { return {*this}; } + IdxRef border() { return {*this}; } const Dimensions& dimensions() const { return dimensions_; } - IdxRef dimensions() { - return {*this}; - } + IdxRef dimensions() { return {*this}; } const Dimensions& minDimensions() const { return minDimensions_; } - IdxRef - minDimensions() { + IdxRef minDimensions() { return {*this}; } const Dimensions& maxDimensions() const { return maxDimensions_; } - IdxRef - maxDimensions() { + IdxRef maxDimensions() { return {*this}; } // Yoga specific properties, not compatible with flexbox specification YGFloatOptional aspectRatio() const { return aspectRatio_; } - Ref aspectRatio() { - return {*this}; - } + Ref aspectRatio() { return {*this}; } }; bool operator==(const YGStyle& lhs, const YGStyle& rhs);