mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-01-18 05:01:13 +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:
parent
95f8fc983b
commit
84e049e23c
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user