Skip to content

Commit

Permalink
Remove cast from detail::Values to std::array<YGValue
Browse files Browse the repository at this point in the history
Summary:
@public

When switching to `CompactValue`, casting edges or dimensions to `std::array<YGValue, ...>` will do actual work.
In order to avoid that from happening implicitely, we remove the casting operator.

Reviewed By: SidharthGuglani

Differential Revision: D13464292

fbshipit-source-id: 217065b001a63cfa8adde715063682c583007a4d
  • Loading branch information
davidaurelio authored and facebook-github-bot committed Dec 14, 2018
1 parent dac5958 commit 0eeb94e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 31 deletions.
5 changes: 2 additions & 3 deletions ReactCommon/fabric/components/view/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,11 @@ inline std::string toString(const YGFloatOptional &value) {
return folly::to<std::string>(floatFromYogaFloat(value.unwrap()));
}

inline std::string toString(
const std::array<YGValue, YGDimensionCount> &value) {
inline std::string toString(const YGStyle::Dimensions &value) {
return "{" + toString(value[0]) + ", " + toString(value[1]) + "}";
}

inline std::string toString(const std::array<YGValue, YGEdgeCount> &value) {
inline std::string toString(const YGStyle::Edges &value) {
static std::array<std::string, YGEdgeCount> names = {{"left",
"top",
"right",
Expand Down
26 changes: 13 additions & 13 deletions ReactCommon/fabric/components/view/propsConversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@
namespace facebook {
namespace react {

static inline std::array<YGValue, 2> convertRawProp(
static inline YGStyle::Dimensions convertRawProp(
const RawProps &rawProps,
const std::string &widthName,
const std::string &heightName,
const std::array<YGValue, 2> &sourceValue,
const std::array<YGValue, 2> &defaultValue) {
auto dimentions = defaultValue;
dimentions[YGDimensionWidth] = convertRawProp(
const YGStyle::Dimensions &sourceValue,
const YGStyle::Dimensions &defaultValue) {
auto dimensions = defaultValue;
dimensions[YGDimensionWidth] = convertRawProp(
rawProps,
widthName,
sourceValue[YGDimensionWidth],
defaultValue[YGDimensionWidth]);
dimentions[YGDimensionHeight] = convertRawProp(
dimensions[YGDimensionHeight] = convertRawProp(
rawProps,
heightName,
sourceValue[YGDimensionHeight],
defaultValue[YGDimensionWidth]);
return dimentions;
return dimensions;
}

static inline std::array<YGValue, YGEdgeCount> convertRawProp(
static inline YGStyle::Edges convertRawProp(
const RawProps &rawProps,
const std::string &prefix,
const std::string &suffix,
const std::array<YGValue, YGEdgeCount> &sourceValue,
const std::array<YGValue, YGEdgeCount> &defaultValue) {
const YGStyle::Edges &sourceValue,
const YGStyle::Edges &defaultValue) {
auto result = defaultValue;
result[YGEdgeLeft] = convertRawProp(
rawProps,
Expand Down Expand Up @@ -88,10 +88,10 @@ static inline std::array<YGValue, YGEdgeCount> convertRawProp(
return result;
}

static inline std::array<YGValue, YGEdgeCount> convertRawProp(
static inline YGStyle::Edges convertRawProp(
const RawProps &rawProps,
const std::array<YGValue, YGEdgeCount> &sourceValue,
const std::array<YGValue, YGEdgeCount> &defaultValue) {
const YGStyle::Edges &sourceValue,
const YGStyle::Edges &defaultValue) {
auto result = defaultValue;
result[YGEdgeLeft] = convertRawProp(
rawProps, "left", sourceValue[YGEdgeLeft], defaultValue[YGEdgeLeft]);
Expand Down
7 changes: 4 additions & 3 deletions ReactCommon/yoga/yoga/YGNodePrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ static void indent(string& base, uint32_t level) {
}
}

static bool areFourValuesEqual(const std::array<YGValue, YGEdgeCount>& four) {
static bool areFourValuesEqual(
const facebook::yoga::detail::Values<YGEdgeCount>& four) {
return YGValueEqual(four[0], four[1]) && YGValueEqual(four[0], four[2]) &&
YGValueEqual(four[0], four[3]);
}
Expand Down Expand Up @@ -81,7 +82,7 @@ appendNumberIfNotZero(string& base, const string& str, const YGValue number) {
static void appendEdges(
string& base,
const string& key,
const std::array<YGValue, YGEdgeCount>& edges) {
const facebook::yoga::detail::Values<YGEdgeCount>& edges) {
if (areFourValuesEqual(edges)) {
appendNumberIfNotZero(base, key, edges[YGEdgeLeft]);
} else {
Expand All @@ -95,7 +96,7 @@ static void appendEdges(
static void appendEdgeIfNotUndefined(
string& base,
const string& str,
const std::array<YGValue, YGEdgeCount>& edges,
const facebook::yoga::detail::Values<YGEdgeCount>& edges,
const YGEdge edge) {
appendNumberIfNotUndefined(
base, str, *YGComputedEdgeValue(edges, edge, &YGValueUndefined));
Expand Down
12 changes: 1 addition & 11 deletions ReactCommon/yoga/yoga/Yoga-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ class Values {
values_.fill(defaultValue);
}

operator const std::array<YGValue, Size>&() const noexcept {
return values_;
}
operator std::array<YGValue, Size>&() noexcept {
return values_;
}
const YGValue& operator[](size_t i) const noexcept {
return values_[i];
}
Expand Down Expand Up @@ -136,10 +130,6 @@ class Values {
}

Values& operator=(const Values& other) = default;
Values& operator=(const std::array<YGValue, Size>& other) noexcept {
values_ = other;
return *this;
}
};

} // namespace detail
Expand All @@ -153,6 +143,6 @@ static const float kWebDefaultFlexShrink = 1.0f;
extern bool YGFloatsEqual(const float a, const float b);
extern bool YGValueEqual(const YGValue a, const YGValue b);
extern const YGValue* YGComputedEdgeValue(
const std::array<YGValue, YGEdgeCount>& edges,
const facebook::yoga::detail::Values<YGEdgeCount>& edges,
const YGEdge edge,
const YGValue* const defaultValue);
2 changes: 1 addition & 1 deletion ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ bool YGFloatIsUndefined(const float value) {
}

const YGValue* YGComputedEdgeValue(
const std::array<YGValue, YGEdgeCount>& edges,
const facebook::yoga::detail::Values<YGEdgeCount>& edges,
const YGEdge edge,
const YGValue* const defaultValue) {
if (edges[edge].unit != YGUnitUndefined) {
Expand Down

0 comments on commit 0eeb94e

Please sign in to comment.