Skip to content

Commit

Permalink
Avoid copying json::Value objects a lot when reallocating vector
Browse files Browse the repository at this point in the history
  • Loading branch information
danpat authored and Patrick Niklaus committed Mar 8, 2018
1 parent c61acaf commit a4ee2cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions include/engine/api/route_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit a4ee2cc

Please sign in to comment.