From 9129a0af87f2ce5f8d038b25edfca38f2fa02fe4 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 14 Sep 2023 23:06:34 -0700 Subject: [PATCH] C++ style enums 2/N: NodeType (#1383) Summary: X-link: https://github.com/facebook/react-native/pull/39450 Pull Request resolved: https://github.com/facebook/yoga/pull/1383 This converts usages of YGNodeType to NodeType Reviewed By: rozele Differential Revision: D49269117 fbshipit-source-id: 27318279fe555c28c605625a160d5be781b662b8 --- yoga/Yoga.cpp | 4 ++-- yoga/algorithm/PixelGrid.cpp | 2 +- yoga/node/Node.cpp | 4 ++-- yoga/node/Node.h | 11 ++++++----- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 34ef7f9f..80d7b257 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -81,11 +81,11 @@ void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout) { } YGNodeType YGNodeGetNodeType(YGNodeConstRef node) { - return resolveRef(node)->getNodeType(); + return unscopedEnum(resolveRef(node)->getNodeType()); } void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType) { - return resolveRef(node)->setNodeType(nodeType); + return resolveRef(node)->setNodeType(scopedEnum(nodeType)); } bool YGNodeIsDirty(YGNodeConstRef node) { diff --git a/yoga/algorithm/PixelGrid.cpp b/yoga/algorithm/PixelGrid.cpp index a9594b24..dce87347 100644 --- a/yoga/algorithm/PixelGrid.cpp +++ b/yoga/algorithm/PixelGrid.cpp @@ -83,7 +83,7 @@ void roundLayoutResultsToPixelGrid( if (pointScaleFactor != 0.0f) { // If a node has a custom measure function we never want to round down its // size as this could lead to unwanted text truncation. - const bool textRounding = node->getNodeType() == YGNodeTypeText; + const bool textRounding = node->getNodeType() == NodeType::Text; node->setLayoutPosition( roundValueToPixelGrid(nodeLeft, pointScaleFactor, false, textRounding), diff --git a/yoga/node/Node.cpp b/yoga/node/Node.cpp index da3438d2..e2b022e0 100644 --- a/yoga/node/Node.cpp +++ b/yoga/node/Node.cpp @@ -227,7 +227,7 @@ void Node::setMeasureFunc(YGMeasureFunc measureFunc) { if (measureFunc == nullptr) { // TODO: t18095186 Move nodeType to opt-in function and mark appropriate // places in Litho - setNodeType(YGNodeTypeDefault); + setNodeType(NodeType::Default); } else { yoga::assertFatalWithNode( this, @@ -236,7 +236,7 @@ void Node::setMeasureFunc(YGMeasureFunc measureFunc) { "children."); // TODO: t18095186 Move nodeType to opt-in function and mark appropriate // places in Litho - setNodeType(YGNodeTypeText); + setNodeType(NodeType::Text); } measureFunc_ = measureFunc; diff --git a/yoga/node/Node.h b/yoga/node/Node.h index 17df371c..e088ab99 100644 --- a/yoga/node/Node.h +++ b/yoga/node/Node.h @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -29,7 +30,7 @@ struct NodeFlags { bool hasNewLayout : 1; bool isReferenceBaseline : 1; bool isDirty : 1; - uint32_t nodeType : 1; + NodeType nodeType : bitCount(); }; #pragma pack(pop) @@ -92,8 +93,8 @@ class YG_EXPORT Node : public ::YGNode { return flags_.hasNewLayout; } - YGNodeType getNodeType() const { - return static_cast(flags_.nodeType); + NodeType getNodeType() const { + return flags_.nodeType; } bool hasMeasureFunc() const noexcept { @@ -250,8 +251,8 @@ class YG_EXPORT Node : public ::YGNode { flags_.hasNewLayout = hasNewLayout; } - void setNodeType(YGNodeType nodeType) { - flags_.nodeType = static_cast(nodeType) & 0x01; + void setNodeType(NodeType nodeType) { + flags_.nodeType = nodeType; } void setMeasureFunc(YGMeasureFunc measureFunc);