From: Kefu Chai Date: Wed, 3 Aug 2022 03:02:52 +0000 (+0800) Subject: common: drop WRITE_{EQ,CMP}_OPERATORS_4() X-Git-Tag: v18.0.0~339^2~4 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=cba426698f3b6314b90a140bfc8b6e256508beae;p=ceph-ci.git common: drop WRITE_{EQ,CMP}_OPERATORS_4() the default-generated comparison operators can fulfill our needs. the order of member variables of `ghobject_t` is adjusted to match the ordering of `ghobject_t`. the default-generated three-way comparison operator uses the order in which the member variables are declared to do the lexical comparison. Signed-off-by: Kefu Chai --- diff --git a/src/common/hobject.h b/src/common/hobject.h index ef27e6f580c..07a23daa511 100644 --- a/src/common/hobject.h +++ b/src/common/hobject.h @@ -379,39 +379,30 @@ static inline int cmp(const T&, const hobject_t&r) { typedef version_t gen_t; struct ghobject_t { - hobject_t hobj; - gen_t generation; - shard_id_t shard_id; - bool max; - -public: static const gen_t NO_GEN = UINT64_MAX; - ghobject_t() - : generation(NO_GEN), - shard_id(shard_id_t::NO_SHARD), - max(false) {} + bool max = false; + shard_id_t shard_id = shard_id_t::NO_SHARD; + hobject_t hobj; + gen_t generation = NO_GEN; + + ghobject_t() = default; explicit ghobject_t(const hobject_t &obj) - : hobj(obj), - generation(NO_GEN), - shard_id(shard_id_t::NO_SHARD), - max(false) {} + : hobj(obj) {} ghobject_t(const hobject_t &obj, gen_t gen, shard_id_t shard) - : hobj(obj), - generation(gen), - shard_id(shard), - max(false) {} + : shard_id(shard), + hobj(obj), + generation(gen) {} // used by Crimson ghobject_t(shard_id_t shard, int64_t pool, uint32_t reversed_hash, const std::string& nspace, const std::string& oid, snapid_t snap, gen_t gen) - : hobj(oid, snap, reversed_hash, pool, nspace), - generation(gen), - shard_id(shard), - max(false) {} + : shard_id(shard), + hobj(oid, snap, reversed_hash, pool, nspace), + generation(gen) {} static ghobject_t make_pgmeta(int64_t pool, uint32_t hash, shard_id_t shard) { hobject_t h(object_t(), std::string(), CEPH_NOSNAP, hash, pool, std::string()); @@ -487,21 +478,8 @@ public: void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list& o); friend int cmp(const ghobject_t& l, const ghobject_t& r); - friend bool operator>(const ghobject_t& l, const ghobject_t& r) { - return cmp(l, r) > 0; - } - friend bool operator>=(const ghobject_t& l, const ghobject_t& r) { - return cmp(l, r) >= 0; - } - friend bool operator<(const ghobject_t& l, const ghobject_t& r) { - return cmp(l, r) < 0; - } - friend bool operator<=(const ghobject_t& l, const ghobject_t& r) { - return cmp(l, r) <= 0; - } - friend bool operator==(const ghobject_t&, const ghobject_t&); - friend bool operator!=(const ghobject_t&, const ghobject_t&); - + auto operator<=>(const ghobject_t&) const = default; + bool operator==(const ghobject_t&) const = default; }; WRITE_CLASS_ENCODER(ghobject_t) @@ -520,8 +498,6 @@ namespace std { std::ostream& operator<<(std::ostream& out, const ghobject_t& o); -WRITE_EQ_OPERATORS_4(ghobject_t, max, shard_id, hobj, generation) - extern int cmp(const ghobject_t& l, const ghobject_t& r); diff --git a/src/include/cmp.h b/src/include/cmp.h index eb47a6259f7..1efe8aa3e47 100644 --- a/src/include/cmp.h +++ b/src/include/cmp.h @@ -4,42 +4,6 @@ /* * macros to define comparison operators for classes with small numbers of members. */ -#define WRITE_EQ_OPERATORS_4(type, a, b, c, d) \ - inline bool operator==(const type &l, const type &r) { \ - return l.a == r.a && l.b == r.b && l.c == r.c && l.d == r.d; \ - } \ - inline bool operator!=(const type &l, const type &r) { \ - return l.a != r.a || l.b != r.b || l.c != r.c || l.d != r.d; \ - } - -#define WRITE_CMP_OPERATORS_4(type, a, b, c, d) \ - inline bool operator>(const type &l, const type &r) { \ - return l.a > r.a || \ - (l.a == r.a && (l.b > r.b || \ - (l.b == r.b && (l.c > r.c || \ - (l.c == r.c && (l.d > r.d)))))); \ - } \ - inline bool operator<(const type &l, const type &r) { \ - return l.a < r.a || \ - (l.a == r.a && (l.b < r.b || \ - (l.b == r.b && (l.c < r.c || \ - (l.c == r.c && (l.d < r.d)))))); \ - } \ - inline bool operator>=(const type &l, const type &r) { \ - return l.a > r.a || \ - (l.a == r.a && (l.b > r.b || \ - (l.b == r.b && (l.c > r.c || \ - (l.c == r.c && (l.d >= r.d)))))); \ - } \ - inline bool operator<=(const type &l, const type &r) { \ - return l.a < r.a || \ - (l.a == r.a && (l.b < r.b || \ - (l.b == r.b && (l.c < r.c || \ - (l.c == r.c && (l.d <= r.d)))))); \ - } - - - #define WRITE_EQ_OPERATORS_5(type, a, b, c, d, e) \ inline bool operator==(const type &l, const type &r) { \ return l.a == r.a && l.b == r.b && l.c == r.c && l.d == r.d && l.e == r.e; \