Apply micro-optimisation for Nearest API (#6944)

This commit is contained in:
Siarhei Fedartsou 2024-06-13 18:18:36 +02:00 committed by GitHub
parent de2f392960
commit aa4e6b1cf3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 7 deletions

View File

@ -24,6 +24,7 @@
- NodeJS: - NodeJS:
- CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452) - CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452)
- Misc: - 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: 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: 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) - CHANGED: Avoid copy of vectors in MakeRoute function. [#6939](https://github.com/Project-OSRM/osrm-backend/pull/6939)

View File

@ -100,23 +100,23 @@ class NearestAPI final : public BaseAPI
auto waypoint = MakeWaypoint({phantom_node}); auto waypoint = MakeWaypoint({phantom_node});
util::json::Array nodes; util::json::Array nodes;
nodes.values.reserve(2);
auto node_values = MakeNodes(phantom_node); auto node_values = MakeNodes(phantom_node);
nodes.values.push_back(node_values.first); nodes.values.emplace_back(node_values.first);
nodes.values.push_back(node_values.second); nodes.values.emplace_back(node_values.second);
waypoint.values["nodes"] = std::move(nodes); waypoint.values.emplace("nodes", std::move(nodes));
return waypoint; 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(); 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);
} }
} }