TBTR: Avoid unnecessary iterations of template replacement pool

This commit is contained in:
Jonathan G Rennison
2020-01-16 01:16:08 +00:00
parent 5a3b67c5c3
commit 424813446f
7 changed files with 62 additions and 24 deletions

View File

@@ -204,12 +204,8 @@ Train* DeleteVirtualTrain(Train *chain, Train *to_del) {
// retrieve template vehicle from template replacement that belongs to the given group
TemplateVehicle* GetTemplateVehicleByGroupID(GroupID gid) {
if (gid >= NEW_GROUP) return nullptr;
for (TemplateReplacement *tr : TemplateReplacement::Iterate()) {
if (tr->Group() == gid) {
return TemplateVehicle::GetIfValid(tr->Template()); // there can be only one
}
}
return nullptr;
const TemplateID tid = GetTemplateIDByGroupID(gid);
return tid != INVALID_TEMPLATE ? TemplateVehicle::GetIfValid(tid) : nullptr;
}
/**