From fac4942b03aea76b6fcf107119ee7a54d2b37a2e Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 3 Aug 2022 10:53:04 +0800 Subject: [PATCH] librados, os: drop WRITE_{EQ,CMP}_OPERATORS_3() the default-generated comparison operators can fulfill our needs. Signed-off-by: Kefu Chai --- src/include/cmp.h | 30 ---------------------------- src/librados/ListObjectImpl.h | 6 ++---- src/os/filestore/SequencerPosition.h | 7 ++----- 3 files changed, 4 insertions(+), 39 deletions(-) diff --git a/src/include/cmp.h b/src/include/cmp.h index 442e11430ffb9..eb47a6259f73c 100644 --- a/src/include/cmp.h +++ b/src/include/cmp.h @@ -4,36 +4,6 @@ /* * macros to define comparison operators for classes with small numbers of members. */ -#define WRITE_EQ_OPERATORS_3(type, a, b, c) \ - inline bool operator==(const type &l, const type &r) { \ - return l.a == r.a && l.b == r.b && l.c == r.c; \ - } \ - inline bool operator!=(const type &l, const type &r) { \ - return l.a != r.a || l.b != r.b || l.c != r.c; \ - } - -#define WRITE_CMP_OPERATORS_3(type, a, b, c) \ - 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)))); \ - } \ - 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)))); \ - } \ - 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)))); \ - } \ - 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)))); \ - } - #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; \ diff --git a/src/librados/ListObjectImpl.h b/src/librados/ListObjectImpl.h index 7396c12108d0c..59ada2e0994f3 100644 --- a/src/librados/ListObjectImpl.h +++ b/src/librados/ListObjectImpl.h @@ -18,8 +18,6 @@ #include #include -#include "include/cmp.h" - namespace librados { struct ListObjectImpl { std::string nspace; @@ -30,12 +28,12 @@ struct ListObjectImpl { ListObjectImpl(std::string n, std::string o, std::string l): nspace(n), oid(o), locator(l) {} + auto operator<=>(const ListObjectImpl&) const = default; + const std::string& get_nspace() const { return nspace; } const std::string& get_oid() const { return oid; } const std::string& get_locator() const { return locator; } }; -WRITE_EQ_OPERATORS_3(ListObjectImpl, nspace, oid, locator) -WRITE_CMP_OPERATORS_3(ListObjectImpl, nspace, oid, locator) inline std::ostream& operator<<(std::ostream& out, const struct ListObjectImpl& lop) { out << (lop.nspace.size() ? lop.nspace + "/" : "") << lop.oid << (lop.locator.size() ? "@" + lop.locator : ""); diff --git a/src/os/filestore/SequencerPosition.h b/src/os/filestore/SequencerPosition.h index 789854317f280..5ba4699a2ff52 100644 --- a/src/os/filestore/SequencerPosition.h +++ b/src/os/filestore/SequencerPosition.h @@ -5,7 +5,6 @@ #define __CEPH_OS_SEQUENCERPOSITION_H #include "include/types.h" -#include "include/cmp.h" #include "include/encoding.h" #include "common/Formatter.h" @@ -21,6 +20,8 @@ struct SequencerPosition { SequencerPosition(uint64_t s=0, int32_t t=0, int32_t o=0) : seq(s), trans(t), op(o) {} + auto operator<=>(const SequencerPosition&) const = default; + void encode(ceph::buffer::list& bl) const { ENCODE_START(1, 1, bl); encode(seq, bl); @@ -52,8 +53,4 @@ inline std::ostream& operator<<(std::ostream& out, const SequencerPosition& t) { return out << t.seq << "." << t.trans << "." << t.op; } -WRITE_EQ_OPERATORS_3(SequencerPosition, seq, trans, op) -WRITE_CMP_OPERATORS_3(SequencerPosition, seq, trans, op) - - #endif -- 2.39.5