Avoid map/set double lookups

Fix some common anti-patterns with these data structures.

- You can dereference the iterator returned by `find` to access the
  underlying value directly, without an extra `operator[]`/`at`.
- Rather than checking for an element before insertion/deletion, you can
  just do the operation and if needed check the return value to
  determine if the insertion/deletion succeeded.
This commit is contained in:
Sintendo 2025-07-06 08:41:12 +02:00
commit f2392e4048
15 changed files with 69 additions and 74 deletions

View file

@ -655,8 +655,9 @@ void NetPlayDialog::UpdateGUI()
auto* name_item = new QTableWidgetItem(QString::fromStdString(p->name));
name_item->setToolTip(name_item->text());
const auto& status_info = player_status.contains(p->game_status) ?
player_status.at(p->game_status) :
const auto it = player_status.find(p->game_status);
const auto& status_info = it != player_status.end() ?
it->second :
std::make_pair(QStringLiteral("?"), QStringLiteral("?"));
auto* status_item = new QTableWidgetItem(status_info.first);
status_item->setToolTip(status_info.second);