Simplify bitfields (#1393)
Summary: X-link: https://github.com/facebook/react-native/pull/39485 Pull Request resolved: https://github.com/facebook/yoga/pull/1393 These were previously packed into structs to allow zero initializing all the flags at once without needing a ctor. C++ 20 has in-class member initializer support for bitfields, which makes these look more like normal member variables. Setting enum values is a bit jank right now, due to relying on C enums which are effectively int32_t, along with GCC `-Wconversion` being a bit aggressive in needing to explicitly mask. I have some ideas to fix this later (e.g. using scoped enums internally). bypass-github-export-checks Changelog: [General][Breaking] - Require C++ 20 when including renderer headers Reviewed By: sammy-SC Differential Revision: D49265967 fbshipit-source-id: 6ab935a866196df06e742c821f3af88eb4d18e1a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
557d2a76fe
commit
ea3869fe9f
@@ -15,14 +15,6 @@
|
||||
|
||||
namespace facebook::yoga {
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
struct LayoutResultFlags {
|
||||
uint32_t direction : 2;
|
||||
bool hadOverflow : 1;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
struct LayoutResults {
|
||||
// This value was chosen based on empirical data:
|
||||
// 98% of analyzed layouts require less than 8 entries.
|
||||
@@ -35,7 +27,8 @@ struct LayoutResults {
|
||||
std::array<float, 4> padding = {};
|
||||
|
||||
private:
|
||||
LayoutResultFlags flags_{};
|
||||
uint32_t direction_ : 2 = static_cast<uint32_t>(YGDirectionInherit) & 0x03;
|
||||
bool hadOverflow_ : 1 = false;
|
||||
|
||||
public:
|
||||
uint32_t computedFlexBasisGeneration = 0;
|
||||
@@ -53,18 +46,18 @@ struct LayoutResults {
|
||||
CachedMeasurement cachedLayout{};
|
||||
|
||||
YGDirection direction() const {
|
||||
return static_cast<YGDirection>(flags_.direction);
|
||||
return static_cast<YGDirection>(direction_);
|
||||
}
|
||||
|
||||
void setDirection(YGDirection direction) {
|
||||
flags_.direction = static_cast<uint32_t>(direction) & 0x03;
|
||||
direction_ = static_cast<uint32_t>(direction) & 0x03;
|
||||
}
|
||||
|
||||
bool hadOverflow() const {
|
||||
return flags_.hadOverflow;
|
||||
return hadOverflow_;
|
||||
}
|
||||
void setHadOverflow(bool hadOverflow) {
|
||||
flags_.hadOverflow = hadOverflow;
|
||||
hadOverflow_ = hadOverflow;
|
||||
}
|
||||
|
||||
bool operator==(LayoutResults layout) const;
|
||||
|
Reference in New Issue
Block a user