Skip to content

Commit

Permalink
Apply micro-optimisation for Table & Trip APIs (Project-OSRM#6949)
Browse files Browse the repository at this point in the history
  • Loading branch information
SiarheiFedartsou authored Jun 15, 2024
1 parent a0eda3e commit feb9389
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- NodeJS:
- CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452)
- Misc:
- CHANGED: Apply micro-optimisation for Table & Trip APIs. [#6949](https://github.com/Project-OSRM/osrm-backend/pull/6949)
- CHANGED: Apply micro-optimisation for Route API. [#6948](https://github.com/Project-OSRM/osrm-backend/pull/6948)
- CHANGED: Apply micro-optimisation for Match API. [#6945](https://github.com/Project-OSRM/osrm-backend/pull/6945)
- CHANGED: Apply micro-optimisation for Nearest API. [#6944](https://github.com/Project-OSRM/osrm-backend/pull/6944)
Expand Down
27 changes: 15 additions & 12 deletions include/engine/api/table_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,58 +179,61 @@ class TableAPI final : public BaseAPI
{
if (!parameters.skip_waypoints)
{
response.values["sources"] = MakeWaypoints(candidates);
response.values.emplace("sources", MakeWaypoints(candidates));
}
number_of_sources = candidates.size();
}
else
{
if (!parameters.skip_waypoints)
{
response.values["sources"] = MakeWaypoints(candidates, parameters.sources);
response.values.emplace("sources", MakeWaypoints(candidates, parameters.sources));
}
}

if (parameters.destinations.empty())
{
if (!parameters.skip_waypoints)
{
response.values["destinations"] = MakeWaypoints(candidates);
response.values.emplace("destinations", MakeWaypoints(candidates));
}
number_of_destinations = candidates.size();
}
else
{
if (!parameters.skip_waypoints)
{
response.values["destinations"] =
MakeWaypoints(candidates, parameters.destinations);
response.values.emplace("destinations",
MakeWaypoints(candidates, parameters.destinations));
}
}

if (parameters.annotations & TableParameters::AnnotationsType::Duration)
{
response.values["durations"] =
MakeDurationTable(tables.first, number_of_sources, number_of_destinations);
response.values.emplace(
"durations",
MakeDurationTable(tables.first, number_of_sources, number_of_destinations));
}

if (parameters.annotations & TableParameters::AnnotationsType::Distance)
{
response.values["distances"] =
MakeDistanceTable(tables.second, number_of_sources, number_of_destinations);
response.values.emplace(
"distances",
MakeDistanceTable(tables.second, number_of_sources, number_of_destinations));
}

if (parameters.fallback_speed != from_alias<double>(INVALID_FALLBACK_SPEED) &&
parameters.fallback_speed > 0)
{
response.values["fallback_speed_cells"] = MakeEstimatesTable(fallback_speed_cells);
response.values.emplace("fallback_speed_cells",
MakeEstimatesTable(fallback_speed_cells));
}

response.values["code"] = "Ok";
response.values.emplace("code", "Ok");
auto data_timestamp = facade.GetTimestamp();
if (!data_timestamp.empty())
{
response.values["data_version"] = data_timestamp;
response.values.emplace("data_version", data_timestamp);
}
}

Expand Down
12 changes: 6 additions & 6 deletions include/engine/api/trip_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ class TripAPI final : public RouteAPI
}
if (!parameters.skip_waypoints)
{
response.values["waypoints"] = MakeWaypoints(sub_trips, candidates);
response.values.emplace("waypoints", MakeWaypoints(sub_trips, candidates));
}
response.values["trips"] = std::move(routes);
response.values["code"] = "Ok";
response.values.emplace("trips", std::move(routes));
response.values.emplace("code", "Ok");
auto data_timestamp = facade.GetTimestamp();
if (!data_timestamp.empty())
{
response.values["data_version"] = data_timestamp;
response.values.emplace("data_version", data_timestamp);
}
}

Expand Down Expand Up @@ -151,8 +151,8 @@ class TripAPI final : public RouteAPI
BOOST_ASSERT(!trip_index.NotUsed());

auto waypoint = BaseAPI::MakeWaypoint(candidates[input_index]);
waypoint.values["trips_index"] = trip_index.sub_trip_index;
waypoint.values["waypoint_index"] = trip_index.point_index;
waypoint.values.emplace("trips_index", trip_index.sub_trip_index);
waypoint.values.emplace("waypoint_index", trip_index.point_index);
waypoints.values.push_back(std::move(waypoint));
}

Expand Down

0 comments on commit feb9389

Please sign in to comment.