From feb938943641e6b34e08cf142b11a1bb7862f56c Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sat, 15 Jun 2024 18:57:26 +0200 Subject: [PATCH] Apply micro-optimisation for Table & Trip APIs (#6949) --- CHANGELOG.md | 1 + include/engine/api/table_api.hpp | 27 +++++++++++++++------------ include/engine/api/trip_api.hpp | 12 ++++++------ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ed316ac803..87627e0c9b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/include/engine/api/table_api.hpp b/include/engine/api/table_api.hpp index 10b57f985d9..82bfe4e3809 100644 --- a/include/engine/api/table_api.hpp +++ b/include/engine/api/table_api.hpp @@ -179,7 +179,7 @@ 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(); } @@ -187,7 +187,7 @@ class TableAPI final : public BaseAPI { 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) { - response.values["destinations"] = MakeWaypoints(candidates); + response.values.emplace("destinations", MakeWaypoints(candidates)); } number_of_destinations = candidates.size(); } @@ -203,34 +203,37 @@ class TableAPI final : public BaseAPI { 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(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); } } diff --git a/include/engine/api/trip_api.hpp b/include/engine/api/trip_api.hpp index 2f821cc1bc5..96486f026e0 100644 --- a/include/engine/api/trip_api.hpp +++ b/include/engine/api/trip_api.hpp @@ -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); } } @@ -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)); }