Avoid redundant calls to DistanceManhattan in town_network_distance

pull/272/head
Jonathan G Rennison 3 years ago
parent e95447edac
commit 1647f9a616

@ -938,11 +938,11 @@ void GeneratePublicRoads()
IncreaseGeneratingWorldProgress(GWP_PUBLIC_ROADS);
auto town_network_distance = [](const TileIndex town, const std::shared_ptr<TownNetwork> &network) {
const auto min_element = std::min_element(network->towns.begin(), network->towns.end(), [&](const TileIndex town_a, const TileIndex town_b) {
return DistanceManhattan(town, town_a) < DistanceManhattan(town, town_b);
});
return DistanceManhattan(*min_element, town);
int32 best = INT32_MAX;
for (TileIndex t : network->towns) {
best = std::min<int32>(best, DistanceManhattan(t, town));
}
return best;
};
sort(towns.begin(), towns.end(), [&](auto a, auto b) { return DistanceManhattan(a, main_town) < DistanceManhattan(b, main_town); });

Loading…
Cancel
Save