[QUEUED scylla next] bytes: compare_unsigned(): change to std::strong_ordering

0 views
Skip to first unread message

Commit Bot

<bot@cloudius-systems.com>
unread,
Jul 29, 2021, 3:44:23 PM7/29/21
to scylladb-dev@googlegroups.com, Avi Kivity
From: Avi Kivity <a...@scylladb.com>
Committer: Avi Kivity <a...@scylladb.com>
Branch: next

bytes: compare_unsigned(): change to std::strong_ordering

Note that the previous implementation was broken for blobs
larger than 4GB. Luckily that can't happen.

Ref #1449.

---
diff --git a/bytes.hh b/bytes.hh
--- a/bytes.hh
+++ b/bytes.hh
@@ -27,6 +27,7 @@
#include <optional>
#include <iosfwd>
#include <functional>
+#include <compare>
#include "utils/mutable_view.hh"
#include <xxhash.h>

@@ -112,13 +113,13 @@ struct hash<bytes_view> {
};
} // namespace std

-inline int32_t compare_unsigned(bytes_view v1, bytes_view v2) {
+inline std::strong_ordering compare_unsigned(bytes_view v1, bytes_view v2) {
auto size = std::min(v1.size(), v2.size());
if (size) {
auto n = memcmp(v1.begin(), v2.begin(), size);
if (n) {
- return n;
+ return n <=> 0;
}
}
- return (int32_t) (v1.size() - v2.size());
+ return v1.size() <=> v2.size();
}

Commit Bot

<bot@cloudius-systems.com>
unread,
Jul 29, 2021, 9:40:12 PM7/29/21
to scylladb-dev@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