diff --git a/CHANGELOG.md b/CHANGELOG.md index cc75331bd4f..2edfeded46b 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 Nearest API. [#6944](/~https://github.com/Project-OSRM/osrm-backend/pull/6944) - CHANGED: Avoid copy of intersection in totalTurnAngle. [#6938](/~https://github.com/Project-OSRM/osrm-backend/pull/6938) - CHANGED: Use std::unordered_map::emplace instead of operator[] when producing JSONs. [#6936](/~https://github.com/Project-OSRM/osrm-backend/pull/6936) - CHANGED: Avoid copy of vectors in MakeRoute function. [#6939](/~https://github.com/Project-OSRM/osrm-backend/pull/6939) diff --git a/include/engine/api/nearest_api.hpp b/include/engine/api/nearest_api.hpp index 32a5898d3db..beae38cec33 100644 --- a/include/engine/api/nearest_api.hpp +++ b/include/engine/api/nearest_api.hpp @@ -100,23 +100,23 @@ class NearestAPI final : public BaseAPI auto waypoint = MakeWaypoint({phantom_node}); util::json::Array nodes; + nodes.values.reserve(2); auto node_values = MakeNodes(phantom_node); - nodes.values.push_back(node_values.first); - nodes.values.push_back(node_values.second); - waypoint.values["nodes"] = std::move(nodes); - + nodes.values.emplace_back(node_values.first); + nodes.values.emplace_back(node_values.second); + waypoint.values.emplace("nodes", std::move(nodes)); return waypoint; }); - response.values["waypoints"] = std::move(waypoints); + response.values.emplace("waypoints", std::move(waypoints)); } - 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); } }