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

Replaces a raw loop that uses array indexes.
This commit is contained in:
Peter Nelson 2025-01-14 19:16:46 +00:00 committed by GitHub
parent 95f8fc983b
commit 84e049e23c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

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