diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-10-07 12:40:35 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-10-29 17:16:37 +0100 |
commit | 93ad5ec32de124dfa0c054acfd1f2a378cb9ca75 (patch) | |
tree | bfe8e842a780cd87ee105806f4112e01784ff7fc /src/gui/setup_players.cpp | |
parent | 63fffadacc51fb7c4915361f0286682e08a55cb1 (diff) | |
download | mana-93ad5ec32de124dfa0c054acfd1f2a378cb9ca75.tar.gz mana-93ad5ec32de124dfa0c054acfd1f2a378cb9ca75.tar.bz2 mana-93ad5ec32de124dfa0c054acfd1f2a378cb9ca75.tar.xz mana-93ad5ec32de124dfa0c054acfd1f2a378cb9ca75.zip |
Optimise PlayerRelationsManager::clear
Previous implementation was O(n^2), doing lots of work (saving file and
updating UI) for each removed player.
Diffstat (limited to 'src/gui/setup_players.cpp')
-rw-r--r-- | src/gui/setup_players.cpp | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index ebe570bb..89c588c0 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -120,7 +120,7 @@ public: return RELATION_CHOICE_COLUMN_WIDTH; } - virtual void playerRelationsUpdated() + void playerRelationsUpdated() { signalBeforeUpdate(); @@ -303,18 +303,11 @@ void Setup_Players::reset() // We now have to search through the list of ignore choices to find the // current selection. We could use an index into the table of config // options in player_relations instead of strategies to sidestep this. - int selection = 0; - for (unsigned int i = 0; - i < player_relations.getPlayerIgnoreStrategies().size(); - ++i) - if (player_relations.getPlayerIgnoreStrategies()[i] == - player_relations.getPlayerIgnoreStrategy()) - { - - selection = i; - break; - } + const auto &strategies = player_relations.getPlayerIgnoreStrategies(); + auto i = std::find(strategies.begin(), strategies.end(), + player_relations.getPlayerIgnoreStrategy()); + int selection = i == strategies.end() ? 0 : i - strategies.begin(); mIgnoreActionChoicesBox->setSelected(selection); } @@ -401,7 +394,7 @@ void Setup_Players::action(const gcn::ActionEvent &event) } } -void Setup_Players::updatedPlayer(const std::string &name) +void Setup_Players::playerRelationsUpdated() { mPlayerTableModel->playerRelationsUpdated(); mDefaultTrading->setSelected( |