1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-30 18:09:09 +00:00

Codechange: Use ranges to get select server list position. (#13316)

Replaces a raw loop that uses array indexes.
This commit is contained in:
2025-01-14 19:16:46 +00:00
committed by GitHub
parent 95f8fc983b
commit 84e049e23c

View File

@@ -325,12 +325,11 @@ protected:
/** Set this->list_pos to match this->server */
void UpdateListPos()
{
this->list_pos = SLP_INVALID;
for (uint i = 0; i != this->servers.size(); i++) {
if (this->servers[i] == this->server) {
this->list_pos = i;
break;
}
auto it = std::ranges::find(this->servers, this->server);
if (it == std::end(this->servers)) {
this->list_pos = SLP_INVALID;
} else {
this->list_pos = static_cast<ServerListPosition>(std::distance(std::begin(this->servers), it));
}
}