Apply micro-optimisation for Table & Trip APIs

This commit is contained in:
Siarhei Fedartsou 2024-06-14 17:54:25 +02:00
parent 7652f6ca6b
commit 864faa7bf9
2 changed files with 21 additions and 18 deletions

View File

@ -179,7 +179,7 @@ class TableAPI final : public BaseAPI
{ {
if (!parameters.skip_waypoints) if (!parameters.skip_waypoints)
{ {
response.values["sources"] = MakeWaypoints(candidates); response.values.emplace("sources", MakeWaypoints(candidates));
} }
number_of_sources = candidates.size(); number_of_sources = candidates.size();
} }
@ -187,7 +187,7 @@ class TableAPI final : public BaseAPI
{ {
if (!parameters.skip_waypoints) if (!parameters.skip_waypoints)
{ {
response.values["sources"] = MakeWaypoints(candidates, parameters.sources); response.values.emplace("sources", MakeWaypoints(candidates, parameters.sources));
} }
} }
@ -195,7 +195,7 @@ class TableAPI final : public BaseAPI
{ {
if (!parameters.skip_waypoints) if (!parameters.skip_waypoints)
{ {
response.values["destinations"] = MakeWaypoints(candidates); response.values.emplace("destinations", MakeWaypoints(candidates));
} }
number_of_destinations = candidates.size(); number_of_destinations = candidates.size();
} }
@ -203,34 +203,37 @@ class TableAPI final : public BaseAPI
{ {
if (!parameters.skip_waypoints) if (!parameters.skip_waypoints)
{ {
response.values["destinations"] = response.values.emplace("destinations",
MakeWaypoints(candidates, parameters.destinations); MakeWaypoints(candidates, parameters.destinations));
} }
} }
if (parameters.annotations & TableParameters::AnnotationsType::Duration) if (parameters.annotations & TableParameters::AnnotationsType::Duration)
{ {
response.values["durations"] = response.values.emplace(
MakeDurationTable(tables.first, number_of_sources, number_of_destinations); "durations",
MakeDurationTable(tables.first, number_of_sources, number_of_destinations));
} }
if (parameters.annotations & TableParameters::AnnotationsType::Distance) if (parameters.annotations & TableParameters::AnnotationsType::Distance)
{ {
response.values["distances"] = response.values.emplace(
MakeDistanceTable(tables.second, number_of_sources, number_of_destinations); "distances",
MakeDistanceTable(tables.second, number_of_sources, number_of_destinations));
} }
if (parameters.fallback_speed != from_alias<double>(INVALID_FALLBACK_SPEED) && if (parameters.fallback_speed != from_alias<double>(INVALID_FALLBACK_SPEED) &&
parameters.fallback_speed > 0) 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(); auto data_timestamp = facade.GetTimestamp();
if (!data_timestamp.empty()) if (!data_timestamp.empty())
{ {
response.values["data_version"] = data_timestamp; response.values.emplace("data_version", data_timestamp);
} }
} }

View File

@ -79,14 +79,14 @@ class TripAPI final : public RouteAPI
} }
if (!parameters.skip_waypoints) 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.emplace("trips", std::move(routes));
response.values["code"] = "Ok"; response.values.emplace("code", "Ok");
auto data_timestamp = facade.GetTimestamp(); auto data_timestamp = facade.GetTimestamp();
if (!data_timestamp.empty()) if (!data_timestamp.empty())
{ {
response.values["data_version"] = data_timestamp; response.values.emplace("data_version", data_timestamp);
} }
} }
@ -151,8 +151,8 @@ class TripAPI final : public RouteAPI
BOOST_ASSERT(!trip_index.NotUsed()); BOOST_ASSERT(!trip_index.NotUsed());
auto waypoint = BaseAPI::MakeWaypoint(candidates[input_index]); auto waypoint = BaseAPI::MakeWaypoint(candidates[input_index]);
waypoint.values["trips_index"] = trip_index.sub_trip_index; waypoint.values.emplace("trips_index", trip_index.sub_trip_index);
waypoint.values["waypoint_index"] = trip_index.point_index; waypoint.values.emplace("waypoint_index", trip_index.point_index);
waypoints.values.push_back(std::move(waypoint)); waypoints.values.push_back(std::move(waypoint));
} }