Skip to content

Commit feb9389

Browse files
Apply micro-optimisation for Table & Trip APIs (#6949)
1 parent a0eda3e commit feb9389

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
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 Table & Trip APIs. [#6949](https://github.com/Project-OSRM/osrm-backend/pull/6949)
2728
- CHANGED: Apply micro-optimisation for Route API. [#6948](https://github.com/Project-OSRM/osrm-backend/pull/6948)
2829
- CHANGED: Apply micro-optimisation for Match API. [#6945](https://github.com/Project-OSRM/osrm-backend/pull/6945)
2930
- CHANGED: Apply micro-optimisation for Nearest API. [#6944](https://github.com/Project-OSRM/osrm-backend/pull/6944)

include/engine/api/table_api.hpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,58 +179,61 @@ class TableAPI final : public BaseAPI
179179
{
180180
if (!parameters.skip_waypoints)
181181
{
182-
response.values["sources"] = MakeWaypoints(candidates);
182+
response.values.emplace("sources", MakeWaypoints(candidates));
183183
}
184184
number_of_sources = candidates.size();
185185
}
186186
else
187187
{
188188
if (!parameters.skip_waypoints)
189189
{
190-
response.values["sources"] = MakeWaypoints(candidates, parameters.sources);
190+
response.values.emplace("sources", MakeWaypoints(candidates, parameters.sources));
191191
}
192192
}
193193

194194
if (parameters.destinations.empty())
195195
{
196196
if (!parameters.skip_waypoints)
197197
{
198-
response.values["destinations"] = MakeWaypoints(candidates);
198+
response.values.emplace("destinations", MakeWaypoints(candidates));
199199
}
200200
number_of_destinations = candidates.size();
201201
}
202202
else
203203
{
204204
if (!parameters.skip_waypoints)
205205
{
206-
response.values["destinations"] =
207-
MakeWaypoints(candidates, parameters.destinations);
206+
response.values.emplace("destinations",
207+
MakeWaypoints(candidates, parameters.destinations));
208208
}
209209
}
210210

211211
if (parameters.annotations & TableParameters::AnnotationsType::Duration)
212212
{
213-
response.values["durations"] =
214-
MakeDurationTable(tables.first, number_of_sources, number_of_destinations);
213+
response.values.emplace(
214+
"durations",
215+
MakeDurationTable(tables.first, number_of_sources, number_of_destinations));
215216
}
216217

217218
if (parameters.annotations & TableParameters::AnnotationsType::Distance)
218219
{
219-
response.values["distances"] =
220-
MakeDistanceTable(tables.second, number_of_sources, number_of_destinations);
220+
response.values.emplace(
221+
"distances",
222+
MakeDistanceTable(tables.second, number_of_sources, number_of_destinations));
221223
}
222224

223225
if (parameters.fallback_speed != from_alias<double>(INVALID_FALLBACK_SPEED) &&
224226
parameters.fallback_speed > 0)
225227
{
226-
response.values["fallback_speed_cells"] = MakeEstimatesTable(fallback_speed_cells);
228+
response.values.emplace("fallback_speed_cells",
229+
MakeEstimatesTable(fallback_speed_cells));
227230
}
228231

229-
response.values["code"] = "Ok";
232+
response.values.emplace("code", "Ok");
230233
auto data_timestamp = facade.GetTimestamp();
231234
if (!data_timestamp.empty())
232235
{
233-
response.values["data_version"] = data_timestamp;
236+
response.values.emplace("data_version", data_timestamp);
234237
}
235238
}
236239

include/engine/api/trip_api.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ class TripAPI final : public RouteAPI
7979
}
8080
if (!parameters.skip_waypoints)
8181
{
82-
response.values["waypoints"] = MakeWaypoints(sub_trips, candidates);
82+
response.values.emplace("waypoints", MakeWaypoints(sub_trips, candidates));
8383
}
84-
response.values["trips"] = std::move(routes);
85-
response.values["code"] = "Ok";
84+
response.values.emplace("trips", std::move(routes));
85+
response.values.emplace("code", "Ok");
8686
auto data_timestamp = facade.GetTimestamp();
8787
if (!data_timestamp.empty())
8888
{
89-
response.values["data_version"] = data_timestamp;
89+
response.values.emplace("data_version", data_timestamp);
9090
}
9191
}
9292

@@ -151,8 +151,8 @@ class TripAPI final : public RouteAPI
151151
BOOST_ASSERT(!trip_index.NotUsed());
152152

153153
auto waypoint = BaseAPI::MakeWaypoint(candidates[input_index]);
154-
waypoint.values["trips_index"] = trip_index.sub_trip_index;
155-
waypoint.values["waypoint_index"] = trip_index.point_index;
154+
waypoint.values.emplace("trips_index", trip_index.sub_trip_index);
155+
waypoint.values.emplace("waypoint_index", trip_index.point_index);
156156
waypoints.values.push_back(std::move(waypoint));
157157
}
158158

0 commit comments

Comments
 (0)