Skip to content

Commit 7652f6c

Browse files
Apply micro-optimisation for Match API (#6945)
1 parent aa4e6b1 commit 7652f6c

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- NodeJS:
2525
- CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452)
2626
- Misc:
27+
- CHANGED: Apply micro-optimisation for Match API. [#6945](https://github.com/Project-OSRM/osrm-backend/pull/6945)
2728
- CHANGED: Apply micro-optimisation for Nearest API. [#6944](https://github.com/Project-OSRM/osrm-backend/pull/6944)
2829
- CHANGED: Avoid copy of intersection in totalTurnAngle. [#6938](https://github.com/Project-OSRM/osrm-backend/pull/6938)
2930
- CHANGED: Use std::unordered_map::emplace instead of operator[] when producing JSONs. [#6936](https://github.com/Project-OSRM/osrm-backend/pull/6936)

include/engine/api/match_api.hpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,19 @@ class MatchAPI final : public RouteAPI
7777
sub_routes[index].unpacked_path_segments,
7878
sub_routes[index].source_traversed_in_reverse,
7979
sub_routes[index].target_traversed_in_reverse);
80-
route.values["confidence"] = sub_matchings[index].confidence;
81-
routes.values.push_back(std::move(route));
80+
route.values.emplace("confidence", sub_matchings[index].confidence);
81+
routes.values.emplace_back(std::move(route));
8282
}
8383
if (!parameters.skip_waypoints)
8484
{
85-
response.values["tracepoints"] = MakeTracepoints(sub_matchings);
85+
response.values.emplace("tracepoints", MakeTracepoints(sub_matchings));
8686
}
87-
response.values["matchings"] = std::move(routes);
88-
response.values["code"] = "Ok";
87+
response.values.emplace("matchings", std::move(routes));
88+
response.values.emplace("code", "Ok");
8989
auto data_timestamp = facade.GetTimestamp();
9090
if (!data_timestamp.empty())
9191
{
92-
response.values["data_version"] = data_timestamp;
92+
response.values.emplace("data_version", data_timestamp);
9393
}
9494
}
9595

@@ -132,13 +132,13 @@ class MatchAPI final : public RouteAPI
132132

133133
if (tidy_result.can_be_removed[trace_index])
134134
{
135-
waypoints.push_back(fbresult::WaypointBuilder(fb_result).Finish());
135+
waypoints.emplace_back(fbresult::WaypointBuilder(fb_result).Finish());
136136
continue;
137137
}
138138
auto matching_index = trace_idx_to_matching_idx[trace_index];
139139
if (matching_index.NotMatched())
140140
{
141-
waypoints.push_back(fbresult::WaypointBuilder(fb_result).Finish());
141+
waypoints.emplace_back(fbresult::WaypointBuilder(fb_result).Finish());
142142
continue;
143143
}
144144
const auto &phantom =
@@ -165,7 +165,7 @@ class MatchAPI final : public RouteAPI
165165
{
166166
waypoint->add_waypoint_index(matching_index.point_index);
167167
}
168-
waypoints.push_back(waypoint->Finish());
168+
waypoints.emplace_back(waypoint->Finish());
169169
}
170170

171171
return fb_result.CreateVector(waypoints);
@@ -186,23 +186,23 @@ class MatchAPI final : public RouteAPI
186186
{
187187
if (tidy_result.can_be_removed[trace_index])
188188
{
189-
waypoints.values.push_back(util::json::Null());
189+
waypoints.values.emplace_back(util::json::Null());
190190
continue;
191191
}
192192
auto matching_index = trace_idx_to_matching_idx[trace_index];
193193
if (matching_index.NotMatched())
194194
{
195-
waypoints.values.push_back(util::json::Null());
195+
waypoints.values.emplace_back(util::json::Null());
196196
continue;
197197
}
198198
const auto &phantom =
199199
sub_matchings[matching_index.sub_matching_index].nodes[matching_index.point_index];
200200
auto waypoint = BaseAPI::MakeWaypoint({phantom});
201-
waypoint.values["matchings_index"] = matching_index.sub_matching_index;
202-
waypoint.values["waypoint_index"] = matching_index.point_index;
203-
waypoint.values["alternatives_count"] =
204-
sub_matchings[matching_index.sub_matching_index]
205-
.alternatives_count[matching_index.point_index];
201+
waypoint.values.emplace("matchings_index", matching_index.sub_matching_index);
202+
waypoint.values.emplace("waypoint_index", matching_index.point_index);
203+
waypoint.values.emplace("alternatives_count",
204+
sub_matchings[matching_index.sub_matching_index]
205+
.alternatives_count[matching_index.point_index]);
206206
// waypoint indices need to be adjusted if route legs were collapsed
207207
// waypoint parameter assumes there is only one match object
208208
if (!parameters.waypoints.empty())
@@ -217,7 +217,7 @@ class MatchAPI final : public RouteAPI
217217
waypoint.values["waypoint_index"] = util::json::Null();
218218
}
219219
}
220-
waypoints.values.push_back(std::move(waypoint));
220+
waypoints.values.emplace_back(std::move(waypoint));
221221
}
222222

223223
return waypoints;

0 commit comments

Comments
 (0)