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

View File

@ -16,6 +16,8 @@
- CHANGED #4845: Updated segregated intersection identification
- Documentation:
- ADDED: Add documentation about OSM node ids in nearest service response [#4436](https://github.com/Project-OSRM/osrm-backend/pull/4436)
- Performance
- FIXED: Speed up response time when lots of legs exist and geojson is used with `steps=true` [#4936](https://github.com/Project-OSRM/osrm-backend/pull/4936)
# 5.16.0

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(),