[QUEUED scylla next] treewide: remove redundant "x <=> 0" compares

0 views
Skip to first unread message

Commit Bot

unread,
Jul 29, 2021, 3:44:34 PMJul 29
to scylla...@googlegroups.com, Avi Kivity
From: Avi Kivity <a...@scylladb.com>
Committer: Avi Kivity <a...@scylladb.com>
Branch: next

treewide: remove redundant "x <=> 0" compares

If x is of type std::strong_ordering, then "x <=> 0" is equivalent to
x. These no-ops were inserted during #1449 fixes, but are now unnecessary.
They have potential for harm, since they can hide an accidental of the
type of x to an arithmetic type, so remove them.

Ref #1449.

---
diff --git a/clustering_bounds_comparator.hh b/clustering_bounds_comparator.hh
--- a/clustering_bounds_comparator.hh
+++ b/clustering_bounds_comparator.hh
@@ -69,7 +69,7 @@ public:
auto res = prefix_equality_tri_compare(type->types().begin(),
type->begin(p1.representation()), type->end(p1.representation()),
type->begin(p2.representation()), type->end(p2.representation()),
- ::tri_compare) <=> 0;
+ ::tri_compare);
if (res != 0) {
return res;
}
diff --git a/compound.hh b/compound.hh
--- a/compound.hh
+++ b/compound.hh
@@ -251,21 +251,21 @@ public:
std::strong_ordering compare(managed_bytes_view b1, managed_bytes_view b2) const {
return with_linearized(b1, [&] (bytes_view bv1) {
return with_linearized(b2, [&] (bytes_view bv2) {
- return compare(bv1, bv2) <=> 0;
+ return compare(bv1, bv2);
});
});
}
std::strong_ordering compare(bytes_view b1, bytes_view b2) const {
if (_byte_order_comparable) {
if (_is_reversed) {
- return compare_unsigned(b2, b1) <=> 0;
+ return compare_unsigned(b2, b1);
} else {
- return compare_unsigned(b1, b2) <=> 0;
+ return compare_unsigned(b1, b2);
}
}
return lexicographical_tri_compare(_types.begin(), _types.end(),
begin(b1), end(b1), begin(b2), end(b2), [] (auto&& type, auto&& v1, auto&& v2) {
- return type->compare(v1, v2) <=> 0;
+ return type->compare(v1, v2);
});
}
// Retruns true iff given prefix has no missing components
diff --git a/compound_compat.hh b/compound_compat.hh
--- a/compound_compat.hh
+++ b/compound_compat.hh
@@ -151,7 +151,7 @@ public:
// @k1 and @k2 must be serialized using @type, which was passed to the constructor.
std::strong_ordering operator()(managed_bytes_view k1, managed_bytes_view k2) const {
if (_type.is_singular()) {
- return compare_unsigned(*_type.begin(k1), *_type.begin(k2)) <=> 0;
+ return compare_unsigned(*_type.begin(k1), *_type.begin(k2));
}
return lexicographical_tri_compare(
_type.begin(k1), _type.end(k1),
@@ -160,7 +160,7 @@ public:
if (c1.size() != c2.size() || !c1.size()) {
return c1.size() < c2.size() ? std::strong_ordering::less : c1.size() ? std::strong_ordering::greater : std::strong_ordering::equal;
}
- return compare_unsigned(c1, c2) <=> 0;
+ return compare_unsigned(c1, c2);
});
}
};
@@ -661,7 +661,7 @@ std::strong_ordering composite::tri_compare::operator()(composite_view v1, compo
auto b_values = v2.components();
auto cmp = [&](const data_type& t, component_view c1, component_view c2) {
// First by value, then by EOC
- auto r = t->compare(c1.first, c2.first) <=> 0;
+ auto r = t->compare(c1.first, c2.first);
if (r != 0) {
return r;
}
diff --git a/cql3/update_parameters.hh b/cql3/update_parameters.hh
--- a/cql3/update_parameters.hh
+++ b/cql3/update_parameters.hh
@@ -83,7 +83,7 @@ public:
const partition_key& pk2, const clustering_key& ck2) const {

std::strong_ordering rc = pk_cmp(pk1, pk2);
- return rc != 0 ? rc : ck_cmp(ck1, ck2) <=> 0;
+ return rc != 0 ? rc : ck_cmp(ck1, ck2);
}
// Allow mixing std::pair<partition_key, clustering_key> and
// std::pair<const partition_key&, const clustering_key&> during lookup
diff --git a/dht/i_partitioner.cc b/dht/i_partitioner.cc
--- a/dht/i_partitioner.cc
+++ b/dht/i_partitioner.cc
@@ -103,7 +103,7 @@ decorated_key::tri_compare(const schema& s, const decorated_key& other) const {
if (r != 0) {
return r;
} else {
- return _key.legacy_tri_compare(s, other._key) <=> 0;
+ return _key.legacy_tri_compare(s, other._key);
}
}

@@ -113,7 +113,7 @@ decorated_key::tri_compare(const schema& s, const ring_position& other) const {
if (r != 0) {
return r;
} else if (other.has_key()) {
- return _key.legacy_tri_compare(s, *other.key()) <=> 0;
+ return _key.legacy_tri_compare(s, *other.key());
}
return 0 <=> other.relation_to_keys();
}
diff --git a/interval.hh b/interval.hh
--- a/interval.hh
+++ b/interval.hh
@@ -112,7 +112,7 @@ private:
template<typename Comparator>
static bool greater_than_or_equal(end_bound_ref end, start_bound_ref start, Comparator&& cmp) {
return !end.b || !start.b || require_ordering_and_on_equal_return(
- cmp(end.b->value(), start.b->value()) <=> 0,
+ cmp(end.b->value(), start.b->value()),
std::strong_ordering::greater,
end.b->is_inclusive() && start.b->is_inclusive());
}
@@ -125,23 +125,23 @@ private:
template<typename Comparator>
static bool less_than_or_equal(start_bound_ref first, start_bound_ref second, Comparator&& cmp) {
return !first.b || (second.b && require_ordering_and_on_equal_return(
- cmp(first.b->value(), second.b->value()) <=> 0,
+ cmp(first.b->value(), second.b->value()),
std::strong_ordering::less,
first.b->is_inclusive() || !second.b->is_inclusive()));
}

template<typename Comparator>
static bool less_than(start_bound_ref first, start_bound_ref second, Comparator&& cmp) {
return second.b && (!first.b || require_ordering_and_on_equal_return(
- cmp(first.b->value(), second.b->value()) <=> 0,
+ cmp(first.b->value(), second.b->value()),
std::strong_ordering::less,
first.b->is_inclusive() && !second.b->is_inclusive()));
}

template<typename Comparator>
static bool greater_than_or_equal(end_bound_ref first, end_bound_ref second, Comparator&& cmp) {
return !first.b || (second.b && require_ordering_and_on_equal_return(
- cmp(first.b->value(), second.b->value()) <=> 0,
+ cmp(first.b->value(), second.b->value()),
std::strong_ordering::greater,
first.b->is_inclusive() || !second.b->is_inclusive()));
}
@@ -284,11 +284,11 @@ public:

if (this_wraps && other_wraps) {
return require_ordering_and_on_equal_return(
- cmp(start()->value(), other.start()->value()) <=> 0,
+ cmp(start()->value(), other.start()->value()),
std::strong_ordering::less,
start()->is_inclusive() || !other.start()->is_inclusive())
&& require_ordering_and_on_equal_return(
- cmp(end()->value(), other.end()->value()) <=> 0,
+ cmp(end()->value(), other.end()->value()),
std::strong_ordering::greater,
end()->is_inclusive() || !other.end()->is_inclusive());
}
@@ -304,11 +304,11 @@ public:

// !other_wraps && this_wraps
return (other.start() && require_ordering_and_on_equal_return(
- cmp(start()->value(), other.start()->value()) <=> 0,
+ cmp(start()->value(), other.start()->value()),
std::strong_ordering::less,
start()->is_inclusive() || !other.start()->is_inclusive()))
|| (other.end() && (require_ordering_and_on_equal_return(
- cmp(end()->value(), other.end()->value()) <=> 0,
+ cmp(end()->value(), other.end()->value()),
std::strong_ordering::greater,
end()->is_inclusive() || !other.end()->is_inclusive())));
}
diff --git a/keys.cc b/keys.cc
--- a/keys.cc
+++ b/keys.cc
@@ -77,7 +77,7 @@ partition_key_view::legacy_form(const schema& s) const {
std::strong_ordering
partition_key_view::legacy_tri_compare(const schema& s, partition_key_view o) const {
auto cmp = legacy_compound_view<c_type>::tri_comparator(*get_compound_type(s));
- return cmp(this->representation(), o.representation()) <=> 0;
+ return cmp(this->representation(), o.representation());
}

std::strong_ordering
diff --git a/keys.hh b/keys.hh
--- a/keys.hh
+++ b/keys.hh
@@ -86,7 +86,7 @@ public:
typename TopLevelView::compound _t;
tri_compare(const schema &s) : _t(get_compound_type(s)) {}
std::strong_ordering operator()(const TopLevelView& k1, const TopLevelView& k2) const {
- return _t->compare(k1.representation(), k2.representation()) <=> 0;
+ return _t->compare(k1.representation(), k2.representation());
}
};

@@ -273,13 +273,13 @@ public:
typename TopLevel::compound _t;
tri_compare(const schema& s) : _t(get_compound_type(s)) {}
std::strong_ordering operator()(const TopLevel& k1, const TopLevel& k2) const {
- return _t->compare(k1.representation(), k2.representation()) <=> 0;
+ return _t->compare(k1.representation(), k2.representation());
}
std::strong_ordering operator()(const TopLevelView& k1, const TopLevel& k2) const {
- return _t->compare(k1.representation(), k2.representation()) <=> 0;
+ return _t->compare(k1.representation(), k2.representation());
}
std::strong_ordering operator()(const TopLevel& k1, const TopLevelView& k2) const {
- return _t->compare(k1.representation(), k2.representation()) <=> 0;
+ return _t->compare(k1.representation(), k2.representation());
}
};

@@ -641,7 +641,7 @@ public:
return prefix_equality_tri_compare(prefix_type->types().begin(),
prefix_type->begin(k1.representation()), prefix_type->end(k1.representation()),
prefix_type->begin(k2.representation()), prefix_type->end(k2.representation()),
- tri_compare) <=> 0;
+ tri_compare);
}
};
};
diff --git a/position_in_partition.hh b/position_in_partition.hh
--- a/position_in_partition.hh
+++ b/position_in_partition.hh
@@ -392,7 +392,7 @@ public:
return lexicographical_tri_compare(types.begin(), types.end(),
a._ck->begin(_s), a._ck->end(_s),
b._ck->begin(_s), b._ck->end(_s),
- cmp, a.relation(), b.relation()) <=> 0;
+ cmp, a.relation(), b.relation());
}

std::strong_ordering operator()(position_in_partition_view a, composite_view b) const {
@@ -412,7 +412,7 @@ public:
return lexicographical_tri_compare(types.begin(), types.end(),
a._ck->begin(_s), a._ck->end(_s),
b_values.begin(), b_values.end(),
- cmp, a.relation(), relation_for_lower_bound(b)) <=> 0;
+ cmp, a.relation(), relation_for_lower_bound(b));
}

std::strong_ordering operator()(composite_view a, position_in_partition_view b) const {
@@ -432,7 +432,7 @@ public:
b_values.begin(), b_values.end(),
cmp,
relation_for_lower_bound(a),
- relation_for_lower_bound(b)) <=> 0;
+ relation_for_lower_bound(b));
}
};

@@ -459,7 +459,7 @@ public:
if (!a._ck) {
return std::strong_ordering::equal;
}
- return _cmp(*a._ck, int8_t(a._bound_weight), *b._ck, int8_t(b._bound_weight)) <=> 0;
+ return _cmp(*a._ck, int8_t(a._bound_weight), *b._ck, int8_t(b._bound_weight));
}
public:
tri_compare(const schema& s) : _cmp(s) { }
diff --git a/sstables/key.hh b/sstables/key.hh
--- a/sstables/key.hh
+++ b/sstables/key.hh
@@ -58,7 +58,7 @@ public:
bool empty() const { return _bytes.empty(); }

std::strong_ordering tri_compare(key_view other) const {
- return compare_unsigned(_bytes, other._bytes) <=> 0;
+ return compare_unsigned(_bytes, other._bytes);
}

std::strong_ordering tri_compare(const schema& s, partition_key_view other) const {
diff --git a/test/boost/btree_test.cc b/test/boost/btree_test.cc
--- a/test/boost/btree_test.cc
+++ b/test/boost/btree_test.cc
@@ -36,7 +36,7 @@ class test_key : public tree_test_key_base {
struct tri_compare {
test_key_tri_compare _cmp;
template <typename A, typename B>
- std::strong_ordering operator()(const A& a, const B& b) const noexcept { return _cmp(a, b) <=> 0; }
+ std::strong_ordering operator()(const A& a, const B& b) const noexcept { return _cmp(a, b); }
};
using test_tree = tree<test_key, &test_key::b_hook, tri_compare, 4, 5, key_search::both, with_debug::yes>;
test_key(int nr, int cookie) noexcept : tree_test_key_base(nr, cookie) {}
diff --git a/test/boost/mutation_test.cc b/test/boost/mutation_test.cc
--- a/test/boost/mutation_test.cc
+++ b/test/boost/mutation_test.cc
@@ -2253,7 +2253,7 @@ class clustering_fragment_summary::tri_cmp {
}
// Range tombstones can have the same start position. In this case use
// the end bound to decide who's "less".
- return _bv_cmp(a.end_bound(), b.end_bound()) <=> 0;
+ return _bv_cmp(a.end_bound(), b.end_bound());
}

public:
diff --git a/test/boost/total_order_check.hh b/test/boost/total_order_check.hh
--- a/test/boost/total_order_check.hh
+++ b/test/boost/total_order_check.hh
@@ -44,7 +44,7 @@ private:
seastar::visit(right_e, [&] (auto&& b) {
testlog.trace("cmp({}, {}) == {}", a, b, order);
auto r = _cmp(a, b);
- auto actual = r <=> 0;
+ auto actual = r;
if (actual != order) {
BOOST_FAIL(format("Expected cmp({}, {}) == {}, but got {}", a, b, order, actual));
}
diff --git a/test/perf/perf_collection.cc b/test/perf/perf_collection.cc
--- a/test/perf/perf_collection.cc
+++ b/test/perf/perf_collection.cc
@@ -59,10 +59,10 @@ class perf_intrusive_key {

struct tri_compare {
key_tri_compare _cmp;
- std::strong_ordering operator()(const per_key_t a, const per_key_t b) const noexcept { return _cmp(a, b) <=> 0; }
- std::strong_ordering operator()(const perf_intrusive_key& a, const perf_intrusive_key& b) const noexcept { return _cmp(a._k, b._k) <=> 0; }
- std::strong_ordering operator()(const per_key_t a, const perf_intrusive_key& b) const noexcept { return _cmp(a, b._k) <=> 0; }
- std::strong_ordering operator()(const perf_intrusive_key& a, const per_key_t b) const noexcept { return _cmp(a._k, b) <=> 0; }
+ std::strong_ordering operator()(const per_key_t a, const per_key_t b) const noexcept { return _cmp(a, b); }
+ std::strong_ordering operator()(const perf_intrusive_key& a, const perf_intrusive_key& b) const noexcept { return _cmp(a._k, b._k); }
+ std::strong_ordering operator()(const per_key_t a, const perf_intrusive_key& b) const noexcept { return _cmp(a, b._k); }
+ std::strong_ordering operator()(const perf_intrusive_key& a, const per_key_t b) const noexcept { return _cmp(a._k, b); }
};
};

diff --git a/types.cc b/types.cc
--- a/types.cc
+++ b/types.cc
@@ -2218,19 +2218,19 @@ struct compare_visitor {
return a <=> b;
});
}
- std::strong_ordering operator()(const string_type_impl&) { return compare_unsigned(v1, v2) <=> 0; }
- std::strong_ordering operator()(const bytes_type_impl&) { return compare_unsigned(v1, v2) <=> 0; }
- std::strong_ordering operator()(const duration_type_impl&) { return compare_unsigned(v1, v2) <=> 0; }
- std::strong_ordering operator()(const inet_addr_type_impl&) { return compare_unsigned(v1, v2) <=> 0; }
+ std::strong_ordering operator()(const string_type_impl&) { return compare_unsigned(v1, v2); }
+ std::strong_ordering operator()(const bytes_type_impl&) { return compare_unsigned(v1, v2); }
+ std::strong_ordering operator()(const duration_type_impl&) { return compare_unsigned(v1, v2); }
+ std::strong_ordering operator()(const inet_addr_type_impl&) { return compare_unsigned(v1, v2); }
std::strong_ordering operator()(const date_type_impl&) {
// This is not the same behaviour as timestamp_type_impl
- return compare_unsigned(v1, v2) <=> 0;
+ return compare_unsigned(v1, v2);
}
std::strong_ordering operator()(const timeuuid_type_impl&) {
return with_empty_checks([&] {
return with_linearized(v1, [&] (bytes_view v1) {
return with_linearized(v2, [&] (bytes_view v2) {
- return utils::timeuuid_tri_compare(v1, v2) <=> 0;
+ return utils::timeuuid_tri_compare(v1, v2);
});
});
});
@@ -2263,11 +2263,11 @@ struct compare_visitor {
if (c1 == 1) {
return with_linearized(v1, [&] (bytes_view v1) {
return with_linearized(v2, [&] (bytes_view v2) {
- return utils::uuid_tri_compare_timeuuid(v1, v2) <=> 0;
+ return utils::uuid_tri_compare_timeuuid(v1, v2);
});
});
}
- return compare_unsigned(v1, v2) <=> 0;
+ return compare_unsigned(v1, v2);
}
std::strong_ordering operator()(const empty_type_impl&) { return std::strong_ordering::equal; }
std::strong_ordering operator()(const tuple_type_impl& t) { return compare_aux(t, v1, v2); }
@@ -2281,7 +2281,7 @@ struct compare_visitor {
return with_empty_checks([&] {
auto a = deserialize_value(d, v1);
auto b = deserialize_value(d, v2);
- return a.compare(b) <=> 0;
+ return a.compare(b);
});
}
std::strong_ordering operator()(const varint_type_impl& v) {

Commit Bot

unread,
Jul 29, 2021, 9:40:22 PMJul 29
to scylla...@googlegroups.com, Avi Kivity
From: Avi Kivity <a...@scylladb.com>
Committer: Avi Kivity <a...@scylladb.com>
Branch: master
Reply all
Reply to author
Forward
0 new messages