@@ -176,6 +176,7 @@ void SelectionWidget::UpdateAvailableScripts()
176176 // maybe also merge it with StartScriptGen.cpp
177177
178178 availableScripts.clear ();
179+ availableScripts.reserve (16 );
179180 // load selected archives to get lua ais
180181
181182 AddAIScriptsFromArchive ();
@@ -184,16 +185,13 @@ void SelectionWidget::UpdateAvailableScripts()
184185 availableScripts.push_back (SandboxAI);
185186
186187 // add native ai's to the list, too (but second, lua ai's are prefered)
187- CAIScriptHandler::ScriptList scriptList = CAIScriptHandler::Instance ().GetScriptList ();
188- for (auto it = scriptList.cbegin (); it != scriptList.cend (); ++it) {
189- availableScripts.push_back (*it);
188+ for (const auto & pair: CAIScriptHandler::Instance ().GetScriptMap ()) {
189+ availableScripts.push_back (pair.first );
190190 }
191191
192- for (std::string &scriptName: availableScripts) {
193- if (scriptName == userScript) {
194- return ;
195- }
196- }
192+ if (std::find (availableScripts.begin (), availableScripts.end (), userScript) != availableScripts.end ())
193+ return ;
194+
197195 SelectScript (SelectionWidget::NoScriptSelect);
198196}
199197
@@ -206,7 +204,7 @@ void SelectionWidget::ShowScriptList()
206204 curSelect->Selected .connect (std::bind (&SelectionWidget::SelectScript, this , std::placeholders::_1));
207205 curSelect->WantClose .connect (std::bind (&SelectionWidget::CleanWindow, this ));
208206
209- for (std::string& scriptName: availableScripts) {
207+ for (const std::string& scriptName: availableScripts) {
210208 curSelect->list ->AddItem (scriptName, " " );
211209 }
212210
0 commit comments