Avoid copying json::Value objects a lot when reallocating vector

This commit is contained in:
Daniel Patterson
2018-03-05 22:45:23 -08:00
committed by Patrick Niklaus
parent c61acaf8be
commit a4ee2ccb13
2 changed files with 8 additions and 2 deletions
+6 -2
View File
@@ -211,12 +211,16 @@ class RouteAPI : public BaseAPI
}
std::vector<util::json::Value> step_geometries;
const auto total_step_count =
std::accumulate(legs.begin(), legs.end(), 0, [](const auto &v, const auto &leg) {
return v + leg.steps.size();
});
step_geometries.reserve(total_step_count);
for (const auto idx : util::irange<std::size_t>(0UL, legs.size()))
{
auto &leg_geometry = leg_geometries[idx];
step_geometries.reserve(step_geometries.size() + legs[idx].steps.size());
std::transform(
legs[idx].steps.begin(),
legs[idx].steps.end(),