Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply micro-optimisation for Table & Trip APIs #6949

Merged
merged 3 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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