Skip to content

Commit df8e02d

Browse files
authored
Depend on operator overload synthesis for three-way and equality comparisons. (flutter#174892)
This depends on the implicitly generated `operator!=` from `operator==` in a few cases (see the exceptions below) and add `operator<=>` in some of the more obvious instances. I've tried to be extremely conservative in this first pass. There are a few more candidates that were not converted because: * `operator!=` was different from `!operator=.` For instance, if it had early returns. Not sure how the compiler generated those and didn't want the behavior or performance characteristics to change. * They were virtual. * `operator==` didn't actually compare all struct members. Dubious but I didn't want to change existing behavior. * There were template parameters.
1 parent f356a80 commit df8e02d

36 files changed

+33
-277
lines changed

engine/src/flutter/display_list/display_list.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,6 @@ class SaveLayerOptions {
243243
bool operator==(const SaveLayerOptions& other) const {
244244
return flags_ == other.flags_;
245245
}
246-
bool operator!=(const SaveLayerOptions& other) const {
247-
return flags_ != other.flags_;
248-
}
249246

250247
private:
251248
union {

engine/src/flutter/display_list/dl_color.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,6 @@ struct DlColor {
181181
green_ == other.green_ && blue_ == other.blue_ &&
182182
color_space_ == other.color_space_;
183183
}
184-
bool operator!=(DlColor const& other) const {
185-
return !this->operator==(other);
186-
}
187184

188185
private:
189186
DlScalar alpha_;

engine/src/flutter/display_list/dl_paint.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ class DlPaint {
203203
}
204204

205205
bool operator==(DlPaint const& other) const;
206-
bool operator!=(DlPaint const& other) const { return !(*this == other); }
207206

208207
private:
209208
#define ASSERT_ENUM_FITS(last_enum, num_bits) \

engine/src/flutter/display_list/dl_vertices.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,6 @@ class DlVertices {
231231

232232
bool operator==(DlVertices const& other) const;
233233

234-
bool operator!=(DlVertices const& other) const { return !(*this == other); }
235-
236234
private:
237235
// Constructors are designed to encapsulate arrays sequentially in memory
238236
// which means they can only be called by intantiations that use the

engine/src/flutter/display_list/geometry/dl_path.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class DlPath : public impeller::PathSource {
9292
DlPathFillType GetFillType() const override;
9393

9494
bool operator==(const DlPath& other) const;
95-
bool operator!=(const DlPath& other) const { return !(*this == other); }
9695

9796
bool IsVolatile() const;
9897
bool IsConvex() const override;

engine/src/flutter/flow/embedded_views.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ class ImageFilterMutation {
5656
return *filter_ == *other.filter_ && filter_rect_ == other.filter_rect_;
5757
}
5858

59-
bool operator!=(const ImageFilterMutation& other) const {
60-
return !operator==(other);
61-
}
62-
6359
private:
6460
std::shared_ptr<DlImageFilter> filter_;
6561
const DlRect filter_rect_;
@@ -107,8 +103,6 @@ class Mutator {
107103

108104
bool operator==(const Mutator& other) const { return data_ == other.data_; }
109105

110-
bool operator!=(const Mutator& other) const { return !operator==(other); }
111-
112106
bool IsClipType() {
113107
switch (GetType()) {
114108
case MutatorType::kClipRect:

engine/src/flutter/flow/raster_cache_key.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ class RasterCacheKeyID {
6464
GetHash() == other.GetHash() && child_ids_ == other.child_ids_;
6565
}
6666

67-
bool operator!=(const RasterCacheKeyID& other) const {
68-
return !operator==(other);
69-
}
70-
7167
private:
7268
const uint64_t unique_id_;
7369
const RasterCacheKeyType type_;

engine/src/flutter/fml/command_line.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class CommandLine final {
6666
bool operator==(const Option& other) const {
6767
return name == other.name && value == other.value;
6868
}
69-
bool operator!=(const Option& other) const { return !operator==(other); }
7069

7170
std::string name;
7271
std::string value;
@@ -103,7 +102,6 @@ class CommandLine final {
103102
options_ == other.options_ &&
104103
positional_args_ == other.positional_args_;
105104
}
106-
bool operator!=(const CommandLine& other) const { return !operator==(other); }
107105

108106
// Returns true if this command line has the option |name| (and if |index| is
109107
// non-null, sets |*index| to the index of the *last* occurrence of the given

engine/src/flutter/fml/time/time_delta.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,7 @@ class TimeDelta {
9696
return TimeDelta::FromNanoseconds(delta_ % other.delta_);
9797
}
9898

99-
bool operator==(TimeDelta other) const { return delta_ == other.delta_; }
100-
bool operator!=(TimeDelta other) const { return delta_ != other.delta_; }
101-
bool operator<(TimeDelta other) const { return delta_ < other.delta_; }
102-
bool operator<=(TimeDelta other) const { return delta_ <= other.delta_; }
103-
bool operator>(TimeDelta other) const { return delta_ > other.delta_; }
104-
bool operator>=(TimeDelta other) const { return delta_ >= other.delta_; }
99+
constexpr auto operator<=>(const TimeDelta& other) const = default;
105100

106101
static constexpr TimeDelta FromTimespec(struct timespec ts) {
107102
return TimeDelta::FromSeconds(ts.tv_sec) +

engine/src/flutter/fml/time/time_point.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,23 @@ class TimePoint {
4949
return TimePoint(ticks);
5050
}
5151

52-
TimeDelta ToEpochDelta() const { return TimeDelta::FromNanoseconds(ticks_); }
52+
constexpr TimeDelta ToEpochDelta() const {
53+
return TimeDelta::FromNanoseconds(ticks_);
54+
}
5355

5456
// Compute the difference between two time points.
55-
TimeDelta operator-(TimePoint other) const {
57+
constexpr TimeDelta operator-(TimePoint other) const {
5658
return TimeDelta::FromNanoseconds(ticks_ - other.ticks_);
5759
}
5860

59-
TimePoint operator+(TimeDelta duration) const {
61+
constexpr TimePoint operator+(TimeDelta duration) const {
6062
return TimePoint(ticks_ + duration.ToNanoseconds());
6163
}
62-
TimePoint operator-(TimeDelta duration) const {
64+
constexpr TimePoint operator-(TimeDelta duration) const {
6365
return TimePoint(ticks_ - duration.ToNanoseconds());
6466
}
6567

66-
bool operator==(TimePoint other) const { return ticks_ == other.ticks_; }
67-
bool operator!=(TimePoint other) const { return ticks_ != other.ticks_; }
68-
bool operator<(TimePoint other) const { return ticks_ < other.ticks_; }
69-
bool operator<=(TimePoint other) const { return ticks_ <= other.ticks_; }
70-
bool operator>(TimePoint other) const { return ticks_ > other.ticks_; }
71-
bool operator>=(TimePoint other) const { return ticks_ >= other.ticks_; }
68+
constexpr auto operator<=>(const TimePoint& other) const = default;
7269

7370
private:
7471
explicit constexpr TimePoint(int64_t ticks) : ticks_(ticks) {}

0 commit comments

Comments
 (0)