refactor: compare_failed spaceship (#8634)

This commit is contained in:
Yat Ho
2026-03-05 06:04:10 +08:00
committed by GitHub
parent 59abf6e1db
commit 4eaf91fda5

View File

@@ -11,6 +11,7 @@
#include <array>
#include <chrono>
#include <compare>
#include <cstdint> // uint64_t
#include <ctime>
#include <optional>
@@ -145,20 +146,20 @@ struct tr_announce_response
* https://www.bittorrent.org/beps/bep_0024.html */
std::optional<tr_address> external_ip;
static constexpr int compare_failed(tr_announce_response const& lhs, tr_announce_response const& rhs) noexcept
static constexpr auto compare_failed(tr_announce_response const& lhs, tr_announce_response const& rhs) noexcept
{
if (auto val = tr_compare_3way(lhs.did_connect, rhs.did_connect); val != 0)
if (auto const val = static_cast<int>(lhs.did_connect) <=> static_cast<int>(rhs.did_connect); val != 0)
{
return val;
}
if (auto val = tr_compare_3way(lhs.did_timeout, rhs.did_timeout); val != 0)
if (auto const val = static_cast<int>(rhs.did_timeout) <=> static_cast<int>(lhs.did_timeout); val != 0)
{
return -val;
return val;
}
// Non-empty error message most likely means we reached the tracker
return -tr_compare_3way(std::empty(lhs.errmsg), std::empty(rhs.errmsg));
return static_cast<int>(std::empty(rhs.errmsg)) <=> static_cast<int>(std::empty(lhs.errmsg));
}
};