aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/misc/guid-inl.h
diff options
context:
space:
mode:
authorbabenko <babenko@yandex-team.com>2023-11-25 17:05:18 +0300
committerbabenko <babenko@yandex-team.com>2023-11-25 17:31:15 +0300
commitef0f7daa4fdd7a8866514cdd37dafdb5ceaa9724 (patch)
tree1fbfae235497e65647a2078d38b50eaec157367e /library/cpp/yt/misc/guid-inl.h
parent6f361c0dc7ed733827aa265049b1204b54292e2e (diff)
downloadydb-ef0f7daa4fdd7a8866514cdd37dafdb5ceaa9724.tar.gz
More TGuid helpers
Diffstat (limited to 'library/cpp/yt/misc/guid-inl.h')
-rw-r--r--library/cpp/yt/misc/guid-inl.h45
1 files changed, 23 insertions, 22 deletions
diff --git a/library/cpp/yt/misc/guid-inl.h b/library/cpp/yt/misc/guid-inl.h
index 1c71d794bd..0e79a3aaa8 100644
--- a/library/cpp/yt/misc/guid-inl.h
+++ b/library/cpp/yt/misc/guid-inl.h
@@ -32,42 +32,43 @@ Y_FORCE_INLINE TGuid::operator bool() const
////////////////////////////////////////////////////////////////////////////////
-Y_FORCE_INLINE bool LessImpl(TGuid lhs, TGuid rhs) noexcept
+Y_FORCE_INLINE bool operator == (TGuid lhs, TGuid rhs) noexcept
+{
+ return
+ lhs.Parts64[0] == rhs.Parts64[0] &&
+ lhs.Parts64[1] == rhs.Parts64[1];
+}
+
+Y_FORCE_INLINE std::strong_ordering operator <=> (TGuid lhs, TGuid rhs) noexcept
{
#ifdef __GNUC__
ui64 lhs0 = __builtin_bswap64(lhs.Parts64[0]);
ui64 rhs0 = __builtin_bswap64(rhs.Parts64[0]);
if (lhs0 < rhs0) {
- return true;
+ return std::strong_ordering::less;
}
if (lhs0 > rhs0) {
- return false;
+ return std::strong_ordering::greater;
}
ui64 lhs1 = __builtin_bswap64(lhs.Parts64[1]);
ui64 rhs1 = __builtin_bswap64(rhs.Parts64[1]);
- return lhs1 < rhs1;
+ if (lhs1 < rhs1) {
+ return std::strong_ordering::less;
+ }
+ if (lhs1 > rhs1) {
+ return std::strong_ordering::greater;
+ }
+ return std::strong_ordering::equal;
#else
- return memcmp(&lhs, &rhs, sizeof(TGuid)) < 0;
-#endif
-}
-
-Y_FORCE_INLINE bool operator == (const TGuid& lhs, const TGuid& rhs) noexcept
-{
- return lhs.Parts64[0] == rhs.Parts64[0] &&
- lhs.Parts64[1] == rhs.Parts64[1];
-}
-
-Y_FORCE_INLINE std::strong_ordering operator <=> (const TGuid& lhs, const TGuid& rhs) noexcept
-{
- if (LessImpl(lhs, rhs)) {
+ int cmp = memcmp(&lhs, &rhs, sizeof(TGuid));
+ if (cmp < 0) {
return std::strong_ordering::less;
}
-
- if (lhs == rhs) {
- return std::strong_ordering::equal;
+ if (cmp > 0) {
+ return std::strong_ordering::greater;
}
-
- return std::strong_ordering::greater;
+ return std::strong_ordering::equal;
+#endif
}
////////////////////////////////////////////////////////////////////////////////