Skip to content

Commit 866bf10

Browse files
amir-shalemfacebook-github-bot
authored andcommitted
Revert D13597449: [Yoga][cleanup] Remove enum count macros
Differential Revision: D13597449 Original commit changeset: edcee225ada4 fbshipit-source-id: 1afc24833c8657a8a198bc4529d98c8f605b7fbd
1 parent 3467308 commit 866bf10

File tree

7 files changed

+48
-87
lines changed

7 files changed

+48
-87
lines changed

yoga/YGConfig.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
#include "Yoga.h"
1111

1212
struct YGConfig {
13-
std::array<bool, facebook::yoga::enums::count<YGExperimentalFeature>()>
14-
experimentalFeatures = {};
13+
std::array<bool, YGExperimentalFeatureCount> experimentalFeatures = {};
1514
bool useWebDefaults = false;
1615
bool useLegacyStretchBehaviour = false;
1716
bool shouldDiffLayoutWithoutLegacyStretchBehaviour = false;

yoga/YGEnums.h

Lines changed: 31 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,14 @@
88

99
#include "YGMacros.h"
1010

11-
#ifdef __cplusplus
12-
namespace facebook {
13-
namespace yoga {
14-
namespace enums {
15-
16-
template <typename T>
17-
constexpr int count() = delete;
18-
19-
namespace detail {
20-
template <int... xs>
21-
constexpr int n() {
22-
return sizeof...(xs);
23-
}
24-
} // namespace detail
25-
26-
} // namespace enums
27-
} // namespace yoga
28-
} // namespace facebook
29-
#endif
30-
3111
#define YG_ENUM_DECL(NAME, ...) \
3212
typedef YG_ENUM_BEGIN(NAME){__VA_ARGS__} YG_ENUM_END(NAME); \
3313
WIN_EXPORT const char* NAME##ToString(NAME);
3414

35-
#ifdef __cplusplus
36-
#define YG_ENUM_SEQ_DECL(NAME, ...) \
37-
YG_ENUM_DECL(NAME, __VA_ARGS__) \
38-
YG_EXTERN_C_END \
39-
namespace facebook { \
40-
namespace yoga { \
41-
namespace enums { \
42-
template <> \
43-
constexpr int count<NAME>() { \
44-
return detail::n<__VA_ARGS__>(); \
45-
} \
46-
} \
47-
} \
48-
} \
49-
YG_EXTERN_C_BEGIN
50-
#else
51-
#define YG_ENUM_SEQ_DECL YG_ENUM_DECL
52-
#endif
53-
5415
YG_EXTERN_C_BEGIN
5516

56-
YG_ENUM_SEQ_DECL(
17+
#define YGAlignCount 8
18+
YG_ENUM_DECL(
5719
YGAlign,
5820
YGAlignAuto,
5921
YGAlignFlexStart,
@@ -64,17 +26,17 @@ YG_ENUM_SEQ_DECL(
6426
YGAlignSpaceBetween,
6527
YGAlignSpaceAround);
6628

67-
YG_ENUM_SEQ_DECL(YGDimension, YGDimensionWidth, YGDimensionHeight)
29+
#define YGDimensionCount 2
30+
YG_ENUM_DECL(YGDimension, YGDimensionWidth, YGDimensionHeight)
6831

69-
YG_ENUM_SEQ_DECL(
70-
YGDirection,
71-
YGDirectionInherit,
72-
YGDirectionLTR,
73-
YGDirectionRTL)
32+
#define YGDirectionCount 3
33+
YG_ENUM_DECL(YGDirection, YGDirectionInherit, YGDirectionLTR, YGDirectionRTL)
7434

75-
YG_ENUM_SEQ_DECL(YGDisplay, YGDisplayFlex, YGDisplayNone)
35+
#define YGDisplayCount 2
36+
YG_ENUM_DECL(YGDisplay, YGDisplayFlex, YGDisplayNone)
7637

77-
YG_ENUM_SEQ_DECL(
38+
#define YGEdgeCount 9
39+
YG_ENUM_DECL(
7840
YGEdge,
7941
YGEdgeLeft,
8042
YGEdgeTop,
@@ -86,16 +48,19 @@ YG_ENUM_SEQ_DECL(
8648
YGEdgeVertical,
8749
YGEdgeAll)
8850

89-
YG_ENUM_SEQ_DECL(YGExperimentalFeature, YGExperimentalFeatureWebFlexBasis)
51+
#define YGExperimentalFeatureCount 1
52+
YG_ENUM_DECL(YGExperimentalFeature, YGExperimentalFeatureWebFlexBasis)
9053

91-
YG_ENUM_SEQ_DECL(
54+
#define YGFlexDirectionCount 4
55+
YG_ENUM_DECL(
9256
YGFlexDirection,
9357
YGFlexDirectionColumn,
9458
YGFlexDirectionColumnReverse,
9559
YGFlexDirectionRow,
9660
YGFlexDirectionRowReverse)
9761

98-
YG_ENUM_SEQ_DECL(
62+
#define YGJustifyCount 6
63+
YG_ENUM_DECL(
9964
YGJustify,
10065
YGJustifyFlexStart,
10166
YGJustifyCenter,
@@ -104,7 +69,8 @@ YG_ENUM_SEQ_DECL(
10469
YGJustifySpaceAround,
10570
YGJustifySpaceEvenly)
10671

107-
YG_ENUM_SEQ_DECL(
72+
#define YGLogLevelCount 6
73+
YG_ENUM_DECL(
10874
YGLogLevel,
10975
YGLogLevelError,
11076
YGLogLevelWarn,
@@ -113,38 +79,35 @@ YG_ENUM_SEQ_DECL(
11379
YGLogLevelVerbose,
11480
YGLogLevelFatal)
11581

116-
YG_ENUM_SEQ_DECL(
82+
#define YGMeasureModeCount 3
83+
YG_ENUM_DECL(
11784
YGMeasureMode,
11885
YGMeasureModeUndefined,
11986
YGMeasureModeExactly,
12087
YGMeasureModeAtMost)
12188

122-
YG_ENUM_SEQ_DECL(YGNodeType, YGNodeTypeDefault, YGNodeTypeText)
89+
#define YGNodeTypeCount 2
90+
YG_ENUM_DECL(YGNodeType, YGNodeTypeDefault, YGNodeTypeText)
12391

124-
YG_ENUM_SEQ_DECL(
125-
YGOverflow,
126-
YGOverflowVisible,
127-
YGOverflowHidden,
128-
YGOverflowScroll)
92+
#define YGOverflowCount 3
93+
YG_ENUM_DECL(YGOverflow, YGOverflowVisible, YGOverflowHidden, YGOverflowScroll)
12994

130-
YG_ENUM_SEQ_DECL(YGPositionType, YGPositionTypeRelative, YGPositionTypeAbsolute)
95+
#define YGPositionTypeCount 2
96+
YG_ENUM_DECL(YGPositionType, YGPositionTypeRelative, YGPositionTypeAbsolute)
13197

98+
#define YGPrintOptionsCount 3
13299
YG_ENUM_DECL(
133100
YGPrintOptions,
134101
YGPrintOptionsLayout = 1,
135102
YGPrintOptionsStyle = 2,
136103
YGPrintOptionsChildren = 4)
137104

138-
YG_ENUM_SEQ_DECL(
139-
YGUnit,
140-
YGUnitUndefined,
141-
YGUnitPoint,
142-
YGUnitPercent,
143-
YGUnitAuto)
105+
#define YGUnitCount 4
106+
YG_ENUM_DECL(YGUnit, YGUnitUndefined, YGUnitPoint, YGUnitPercent, YGUnitAuto)
144107

145-
YG_ENUM_SEQ_DECL(YGWrap, YGWrapNoWrap, YGWrapWrap, YGWrapWrapReverse)
108+
#define YGWrapCount 3
109+
YG_ENUM_DECL(YGWrap, YGWrapNoWrap, YGWrapWrap, YGWrapWrapReverse)
146110

147111
YG_EXTERN_C_END
148112

149113
#undef YG_ENUM_DECL
150-
#undef YG_ENUM_SEQ_DECL

yoga/YGNode.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ YGValue YGNode::resolveFlexBasisPtr() const {
313313
}
314314

315315
void YGNode::resolveDimension() {
316-
using namespace yoga;
317-
for (int dim = YGDimensionWidth; dim < enums::count<YGDimension>(); dim++) {
316+
for (uint32_t dim = YGDimensionWidth; dim < YGDimensionCount; dim++) {
318317
if (!getStyle().maxDimensions[dim].isUndefined() &&
319318
YGValueEqual(
320319
getStyle().maxDimensions[dim], style_.minDimensions[dim])) {

yoga/YGNodePrint.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ static void indent(string& base, uint32_t level) {
2020
}
2121
}
2222

23-
static bool areFourValuesEqual(const YGStyle::Edges& four) {
23+
static bool areFourValuesEqual(
24+
const facebook::yoga::detail::Values<YGEdgeCount>& four) {
2425
return YGValueEqual(four[0], four[1]) && YGValueEqual(four[0], four[2]) &&
2526
YGValueEqual(four[0], four[3]);
2627
}
@@ -85,7 +86,7 @@ static void appendNumberIfNotZero(
8586
static void appendEdges(
8687
string& base,
8788
const string& key,
88-
const YGStyle::Edges& edges) {
89+
const facebook::yoga::detail::Values<YGEdgeCount>& edges) {
8990
if (areFourValuesEqual(edges)) {
9091
appendNumberIfNotZero(base, key, edges[YGEdgeLeft]);
9192
} else {
@@ -99,7 +100,7 @@ static void appendEdges(
99100
static void appendEdgeIfNotUndefined(
100101
string& base,
101102
const string& str,
102-
const YGStyle::Edges& edges,
103+
const facebook::yoga::detail::Values<YGEdgeCount>& edges,
103104
const YGEdge edge) {
104105
appendNumberIfNotUndefined(
105106
base,

yoga/YGStyle.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <array>
1010
#include <initializer_list>
1111
#include "CompactValue.h"
12-
#include "YGEnums.h"
1312
#include "YGFloatOptional.h"
1413
#include "Yoga-internal.h"
1514
#include "Yoga.h"
@@ -30,8 +29,7 @@ struct YGStyle {
3029

3130
public:
3231
using Dimensions = facebook::yoga::detail::Values<2>;
33-
using Edges =
34-
facebook::yoga::detail::Values<facebook::yoga::enums::count<YGEdge>()>;
32+
using Edges = facebook::yoga::detail::Values<YGEdgeCount>;
3533

3634
/* Some platforms don't support enum bitfields,
3735
so please use BITFIELD_ENUM_SIZED(BITS_COUNT) */

yoga/Yoga-internal.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ static const float kWebDefaultFlexShrink = 1.0f;
149149
extern bool YGFloatsEqual(const float a, const float b);
150150
extern bool YGValueEqual(const YGValue a, const YGValue b);
151151
extern facebook::yoga::detail::CompactValue YGComputedEdgeValue(
152-
const facebook::yoga::detail::Values<
153-
facebook::yoga::enums::count<YGEdge>()>& edges,
152+
const facebook::yoga::detail::Values<YGEdgeCount>& edges,
154153
YGEdge edge,
155154
facebook::yoga::detail::CompactValue defaultValue);

yoga/Yoga.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ bool YGFloatIsUndefined(const float value) {
105105
}
106106

107107
detail::CompactValue YGComputedEdgeValue(
108-
const YGStyle::Edges& edges,
108+
const facebook::yoga::detail::Values<YGEdgeCount>& edges,
109109
YGEdge edge,
110110
detail::CompactValue defaultValue) {
111111
if (!edges[edge].isUndefined()) {
@@ -3546,12 +3546,14 @@ static const char* YGSpacer(const unsigned long level) {
35463546
static const char* YGMeasureModeName(
35473547
const YGMeasureMode mode,
35483548
const bool performLayout) {
3549-
constexpr auto N = enums::count<YGMeasureMode>();
3550-
const char* kMeasureModeNames[N] = {"UNDEFINED", "EXACTLY", "AT_MOST"};
3551-
const char* kLayoutModeNames[N] = {
3552-
"LAY_UNDEFINED", "LAY_EXACTLY", "LAY_AT_MOST"};
3553-
3554-
if (mode >= N) {
3549+
const char* kMeasureModeNames[YGMeasureModeCount] = {
3550+
"UNDEFINED", "EXACTLY", "AT_MOST"};
3551+
const char* kLayoutModeNames[YGMeasureModeCount] = {"LAY_UNDEFINED",
3552+
"LAY_EXACTLY",
3553+
"LAY_AT_"
3554+
"MOST"};
3555+
3556+
if (mode >= YGMeasureModeCount) {
35553557
return "";
35563558
}
35573559

0 commit comments

Comments
 (0)