From e69c065d6e0e382910c0038ee021725bbccfefc3 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 17 Jul 2024 11:40:17 +0100 Subject: [PATCH] Codechange: Use find_if to find waypoint StationSpec when converting old savegames. (#12865) This simplifies an indexed loop. --- src/saveload/waypoint_sl.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/saveload/waypoint_sl.cpp b/src/saveload/waypoint_sl.cpp index 7745c9b6e5..9dc9de2376 100644 --- a/src/saveload/waypoint_sl.cpp +++ b/src/saveload/waypoint_sl.cpp @@ -86,14 +86,9 @@ void MoveWaypointsToBaseStations() /* As of version 17, we recalculate the custom graphic ID of waypoints * from the GRF ID / station index. */ for (OldWaypoint &wp : _old_waypoints) { - StationClass *stclass = StationClass::Get(STAT_CLASS_WAYP); - for (uint i = 0; i < stclass->GetSpecCount(); i++) { - const StationSpec *statspec = stclass->GetSpec(i); - if (statspec != nullptr && statspec->grf_prop.grffile->grfid == wp.grfid && statspec->grf_prop.local_id == wp.localidx) { - wp.spec = statspec; - break; - } - } + const auto specs = StationClass::Get(STAT_CLASS_WAYP)->Specs(); + auto found = std::find_if(std::begin(specs), std::end(specs), [&wp](const StationSpec *spec) { return spec != nullptr && spec->grf_prop.grffile->grfid == wp.grfid && spec->grf_prop.local_id == wp.localidx; }); + if (found != std::end(specs)) wp.spec = *found; } }