[QUEUED scylla next] atomic_cell: change compare_atomic_cell_for_merge() to std::strong_ordering

0 views
Skip to first unread message

Commit Bot

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

atomic_cell: change compare_atomic_cell_for_merge() to std::strong_ordering

The implementation is in database.cc for some reason.

Ref #1449.

---
diff --git a/atomic_cell.hh b/atomic_cell.hh
--- a/atomic_cell.hh
+++ b/atomic_cell.hh
@@ -396,7 +396,7 @@ public:

class column_definition;

-int compare_atomic_cell_for_merge(atomic_cell_view left, atomic_cell_view right);
+std::strong_ordering compare_atomic_cell_for_merge(atomic_cell_view left, atomic_cell_view right);
void merge_column(const abstract_type& def,
atomic_cell_or_collection& old,
const atomic_cell_or_collection& neww);
diff --git a/database.cc b/database.cc
--- a/database.cc
+++ b/database.cc
@@ -1364,25 +1364,25 @@ database::existing_index_names(const sstring& ks_name, const sstring& cf_to_excl
// - org.apache.cassandra.db.AbstractCell#reconcile()
// - org.apache.cassandra.db.BufferExpiringCell#reconcile()
// - org.apache.cassandra.db.BufferDeletedCell#reconcile()
-int
+std::strong_ordering
compare_atomic_cell_for_merge(atomic_cell_view left, atomic_cell_view right) {
if (left.timestamp() != right.timestamp()) {
- return left.timestamp() > right.timestamp() ? 1 : -1;
+ return left.timestamp() <=> right.timestamp();
}
if (left.is_live() != right.is_live()) {
- return left.is_live() ? -1 : 1;
+ return left.is_live() ? std::strong_ordering::less : std::strong_ordering::greater;
}
if (left.is_live()) {
- auto c = compare_unsigned(left.value(), right.value());
+ auto c = compare_unsigned(left.value(), right.value()) <=> 0;
if (c != 0) {
return c;
}
if (left.is_live_and_has_ttl() != right.is_live_and_has_ttl()) {
// prefer expiring cells.
- return left.is_live_and_has_ttl() ? 1 : -1;
+ return left.is_live_and_has_ttl() ? std::strong_ordering::greater : std::strong_ordering::less;
}
if (left.is_live_and_has_ttl() && left.expiry() != right.expiry()) {
- return left.expiry() < right.expiry() ? -1 : 1;
+ return left.expiry() <=> right.expiry();
}
} else {
// Both are deleted
@@ -1392,10 +1392,10 @@ compare_atomic_cell_for_merge(atomic_cell_view left, atomic_cell_view right) {
// comparing timestamps, which in case of deleted cells will hold
// serialized expiry.
return (uint64_t) left.deletion_time().time_since_epoch().count()
- < (uint64_t) right.deletion_time().time_since_epoch().count() ? -1 : 1;
+ <=> (uint64_t) right.deletion_time().time_since_epoch().count();
}
}
- return 0;
+ return std::strong_ordering::equal;
}

future<std::tuple<lw_shared_ptr<query::result>, cache_temperature>>

Commit Bot

unread,
Jul 29, 2021, 9:40:15 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