]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common: drop WRITE_{EQ,CMP}_OPERATORS_4()
authorKefu Chai <tchaikov@gmail.com>
Wed, 3 Aug 2022 03:02:52 +0000 (11:02 +0800)
committerKefu Chai <tchaikov@gmail.com>
Thu, 4 Aug 2022 13:33:51 +0000 (21:33 +0800)
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 <tchaikov@gmail.com>
src/common/hobject.h
src/include/cmp.h

index ef27e6f580ce6680f80f8fd33207e1759ef8e626..07a23daa5115edcf98a7a53b37f50102aa2e1694 100644 (file)
@@ -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<ghobject_t*>& 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);
 
 
index eb47a6259f73c58541911f1be5213ef1f8876715..1efe8aa3e47ce08922dbd9daafa438a6ae406e7c 100644 (file)
@@ -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; \