Skip to content

Commit 5993308

Browse files
NickGerlemanmeta-codesync[bot]
authored andcommitted
Default operator== definitions in react-native-github (#55750)
Summary: Pull Request resolved: #55750 Replace explicit `operator==` implementations with `= default` where the operator performs simple memberwise comparison of all data members. The compiler-generated defaulted operator is equivalent but less error-prone and easier to maintain as members are added or removed. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D94371201 fbshipit-source-id: 6510ba4a5c5eca4f8d5c2ca363e4d28df63f58b6
1 parent f5a921f commit 5993308

File tree

13 files changed

+20
-164
lines changed

13 files changed

+20
-164
lines changed

packages/react-native/ReactCommon/react/renderer/components/scrollview/primitives.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ class ScrollViewMaintainVisibleContentPosition final {
2525
int minIndexForVisible{0};
2626
std::optional<int> autoscrollToTopThreshold{};
2727

28-
bool operator==(const ScrollViewMaintainVisibleContentPosition &rhs) const
29-
{
30-
return std::tie(this->minIndexForVisible, this->autoscrollToTopThreshold) ==
31-
std::tie(rhs.minIndexForVisible, rhs.autoscrollToTopThreshold);
32-
}
28+
bool operator==(const ScrollViewMaintainVisibleContentPosition &rhs) const = default;
3329
};
3430

3531
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/components/view/primitives.h

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -178,35 +178,7 @@ struct CascadedRectangleEdges {
178178
};
179179
}
180180

181-
bool operator==(const CascadedRectangleEdges<T> &rhs) const
182-
{
183-
return std::tie(
184-
this->left,
185-
this->top,
186-
this->right,
187-
this->bottom,
188-
this->start,
189-
this->end,
190-
this->horizontal,
191-
this->vertical,
192-
this->all,
193-
this->block,
194-
this->blockStart,
195-
this->blockEnd) ==
196-
std::tie(
197-
rhs.left,
198-
rhs.top,
199-
rhs.right,
200-
rhs.bottom,
201-
rhs.start,
202-
rhs.end,
203-
rhs.horizontal,
204-
rhs.vertical,
205-
rhs.all,
206-
rhs.block,
207-
rhs.blockStart,
208-
rhs.blockEnd);
209-
}
181+
bool operator==(const CascadedRectangleEdges<T> &rhs) const = default;
210182
};
211183

212184
template <typename T>
@@ -251,37 +223,7 @@ struct CascadedRectangleCorners {
251223
};
252224
}
253225

254-
bool operator==(const CascadedRectangleCorners<T> &rhs) const
255-
{
256-
return std::tie(
257-
this->topLeft,
258-
this->topRight,
259-
this->bottomLeft,
260-
this->bottomRight,
261-
this->topStart,
262-
this->topEnd,
263-
this->bottomStart,
264-
this->bottomEnd,
265-
this->all,
266-
this->endEnd,
267-
this->endStart,
268-
this->startEnd,
269-
this->startStart) ==
270-
std::tie(
271-
rhs.topLeft,
272-
rhs.topRight,
273-
rhs.bottomLeft,
274-
rhs.bottomRight,
275-
rhs.topStart,
276-
rhs.topEnd,
277-
rhs.bottomStart,
278-
rhs.bottomEnd,
279-
rhs.all,
280-
rhs.endEnd,
281-
rhs.endStart,
282-
rhs.startEnd,
283-
rhs.startStart);
284-
}
226+
bool operator==(const CascadedRectangleCorners<T> &rhs) const = default;
285227
};
286228

287229
using BorderWidths = RectangleEdges<Float>;
@@ -303,12 +245,7 @@ struct BorderMetrics {
303245
BorderCurves borderCurves{};
304246
BorderStyles borderStyles{};
305247

306-
bool operator==(const BorderMetrics &rhs) const
307-
{
308-
return std::tie(
309-
this->borderColors, this->borderWidths, this->borderRadii, this->borderCurves, this->borderStyles) ==
310-
std::tie(rhs.borderColors, rhs.borderWidths, rhs.borderRadii, rhs.borderCurves, rhs.borderStyles);
311-
}
248+
bool operator==(const BorderMetrics &rhs) const = default;
312249
};
313250

314251
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/css/CSSBackgroundImage.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,7 @@ static_assert(CSSDataType<CSSLinearGradientDirection>);
169169
struct CSSColorHint {
170170
std::variant<CSSLength, CSSPercentage> position{}; // Support both lengths and percentages
171171

172-
bool operator==(const CSSColorHint &rhs) const
173-
{
174-
return position == rhs.position;
175-
}
172+
bool operator==(const CSSColorHint &rhs) const = default;
176173
};
177174

178175
template <>
@@ -423,10 +420,7 @@ struct CSSRadialGradientPosition {
423420
std::optional<std::variant<CSSLength, CSSPercentage>> left{};
424421
std::optional<std::variant<CSSLength, CSSPercentage>> right{};
425422

426-
bool operator==(const CSSRadialGradientPosition &rhs) const
427-
{
428-
return top == rhs.top && bottom == rhs.bottom && left == rhs.left && right == rhs.right;
429-
}
423+
bool operator==(const CSSRadialGradientPosition &rhs) const = default;
430424
};
431425

432426
struct CSSRadialGradientFunction {

packages/react-native/ReactCommon/react/renderer/graphics/LinearGradient.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ struct GradientDirection {
3131
GradientDirectionType type;
3232
std::variant<Float, GradientKeyword> value;
3333

34-
bool operator==(const GradientDirection &other) const
35-
{
36-
return type == other.type && value == other.value;
37-
}
34+
bool operator==(const GradientDirection &other) const = default;
3835

3936
#ifdef RN_SERIALIZABLE_STATE
4037
folly::dynamic toDynamic() const;
@@ -45,10 +42,7 @@ struct LinearGradient {
4542
GradientDirection direction;
4643
std::vector<ColorStop> colorStops;
4744

48-
bool operator==(const LinearGradient &other) const
49-
{
50-
return direction == other.direction && colorStops == other.colorStops;
51-
}
45+
bool operator==(const LinearGradient &other) const = default;
5246

5347
#ifdef RN_SERIALIZABLE_STATE
5448
folly::dynamic toDynamic() const;

packages/react-native/ReactCommon/react/renderer/graphics/RadialGradient.h

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ struct RadialGradientSize {
3131
ValueUnit x;
3232
ValueUnit y;
3333

34-
bool operator==(const Dimensions &other) const
35-
{
36-
return x == other.x && y == other.y;
37-
}
34+
bool operator==(const Dimensions &other) const = default;
3835

3936
#ifdef RN_SERIALIZABLE_STATE
4037
folly::dynamic toDynamic() const;
@@ -43,10 +40,7 @@ struct RadialGradientSize {
4340

4441
std::variant<SizeKeyword, Dimensions> value;
4542

46-
bool operator==(const RadialGradientSize &other) const
47-
{
48-
return value == other.value;
49-
}
43+
bool operator==(const RadialGradientSize &other) const = default;
5044

5145
#ifdef RN_SERIALIZABLE_STATE
5246
folly::dynamic toDynamic() const;
@@ -59,10 +53,7 @@ struct RadialGradientPosition {
5953
std::optional<ValueUnit> right;
6054
std::optional<ValueUnit> bottom;
6155

62-
bool operator==(const RadialGradientPosition &other) const
63-
{
64-
return top == other.top && left == other.left && right == other.right && bottom == other.bottom;
65-
}
56+
bool operator==(const RadialGradientPosition &other) const = default;
6657

6758
#ifdef RN_SERIALIZABLE_STATE
6859
folly::dynamic toDynamic() const;
@@ -75,10 +66,7 @@ struct RadialGradient {
7566
RadialGradientPosition position;
7667
std::vector<ColorStop> colorStops;
7768

78-
bool operator==(const RadialGradient &other) const
79-
{
80-
return shape == other.shape && size == other.size && position == other.position && colorStops == other.colorStops;
81-
}
69+
bool operator==(const RadialGradient &other) const = default;
8270

8371
#ifdef RN_SERIALIZABLE_STATE
8472
folly::dynamic toDynamic() const;

packages/react-native/ReactCommon/react/renderer/graphics/Rect.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ struct Rect {
2424
Point origin{.x = 0, .y = 0};
2525
Size size{.width = 0, .height = 0};
2626

27-
bool operator==(const Rect &rhs) const noexcept
28-
{
29-
return std::tie(this->origin, this->size) == std::tie(rhs.origin, rhs.size);
30-
}
27+
bool operator==(const Rect &rhs) const noexcept = default;
3128

3229
Float getMaxX() const noexcept
3330
{

packages/react-native/ReactCommon/react/renderer/graphics/RectangleCorners.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ struct RectangleCorners {
2525
T bottomLeft{};
2626
T bottomRight{};
2727

28-
bool operator==(const RectangleCorners<T> &rhs) const noexcept
29-
{
30-
return std::tie(this->topLeft, this->topRight, this->bottomLeft, this->bottomRight) ==
31-
std::tie(rhs.topLeft, rhs.topRight, rhs.bottomLeft, rhs.bottomRight);
32-
}
28+
bool operator==(const RectangleCorners<T> &rhs) const noexcept = default;
3329

3430
bool isUniform() const noexcept
3531
{

packages/react-native/ReactCommon/react/renderer/graphics/RectangleEdges.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ struct RectangleEdges {
2626
T right{};
2727
T bottom{};
2828

29-
bool operator==(const RectangleEdges<T> &rhs) const noexcept
30-
{
31-
return std::tie(this->left, this->top, this->right, this->bottom) ==
32-
std::tie(rhs.left, rhs.top, rhs.right, rhs.bottom);
33-
}
29+
bool operator==(const RectangleEdges<T> &rhs) const noexcept = default;
3430

3531
bool isUniform() const noexcept
3632
{

packages/react-native/ReactCommon/react/renderer/graphics/Transform.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ struct TransformOrigin {
4949
std::array<ValueUnit, 2> xy = {ValueUnit(0.0f, UnitType::Undefined), ValueUnit(0.0f, UnitType::Undefined)};
5050
float z = 0.0f;
5151

52-
bool operator==(const TransformOrigin &other) const
53-
{
54-
return xy[0] == other.xy[0] && xy[1] == other.xy[1] && z == other.z;
55-
}
52+
bool operator==(const TransformOrigin &other) const = default;
5653
bool isSet() const
5754
{
5855
return xy[0].value != 0.0f || xy[0].unit != UnitType::Undefined || xy[1].value != 0.0f ||

packages/react-native/ReactCommon/react/renderer/graphics/ValueUnit.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ struct ValueUnit {
2929
constexpr ValueUnit() = default;
3030
constexpr ValueUnit(float v, UnitType u) : value(v), unit(u) {}
3131

32-
constexpr bool operator==(const ValueUnit &other) const
33-
{
34-
return value == other.value && unit == other.unit;
35-
}
32+
constexpr bool operator==(const ValueUnit &other) const = default;
3633

3734
constexpr float resolve(float referenceLength) const
3835
{

0 commit comments

Comments
 (0)