@@ -44,21 +44,22 @@ util::json::Array lanesFromIntersection(const guidance::IntermediateIntersection
44
44
{
45
45
BOOST_ASSERT (intersection.lanes .lanes_in_turn >= 1 );
46
46
util::json::Array result;
47
+ result.values .reserve (intersection.lane_description .size ());
47
48
LaneID lane_id = intersection.lane_description .size ();
48
49
49
50
for (const auto &lane_desc : intersection.lane_description )
50
51
{
51
52
--lane_id;
52
53
util::json::Object lane;
53
- lane.values [ " indications" ] = toJSON (lane_desc);
54
+ lane.values . emplace ( " indications" , toJSON (lane_desc) );
54
55
if (lane_id >= intersection.lanes .first_lane_from_the_right &&
55
56
lane_id <
56
57
intersection.lanes .first_lane_from_the_right + intersection.lanes .lanes_in_turn )
57
- lane.values [ " valid" ] = util::json::True ();
58
+ lane.values . emplace ( " valid" , util::json::True () );
58
59
else
59
- lane.values [ " valid" ] = util::json::False ();
60
+ lane.values . emplace ( " valid" , util::json::False () );
60
61
61
- result.values .push_back ( lane);
62
+ result.values .emplace_back ( std::move ( lane) );
62
63
}
63
64
64
65
return result;
@@ -77,6 +78,7 @@ std::string waypointTypeToString(const guidance::WaypointType waypoint_type)
77
78
util::json::Value coordinateToLonLat (const util::Coordinate &coordinate)
78
79
{
79
80
util::json::Array array;
81
+ array.values .reserve (2 );
80
82
array.values .push_back (static_cast <double >(util::toFloating (coordinate.lon )));
81
83
array.values .push_back (static_cast <double >(util::toFloating (coordinate.lat )));
82
84
return util::json::Value{std::move (array)};
@@ -98,17 +100,20 @@ util::json::Object makeStepManeuver(const guidance::StepManeuver &maneuver)
98
100
// These invalid responses should never happen: log if they do happen
99
101
BOOST_ASSERT_MSG (maneuver_type != " invalid" , " unexpected invalid maneuver type" );
100
102
101
- step_maneuver.values [ " type" ] = std::move (maneuver_type);
103
+ step_maneuver.values . emplace ( " type" , std::move (maneuver_type) );
102
104
103
105
if (detail::isValidModifier (maneuver))
104
- step_maneuver.values [" modifier" ] =
105
- osrm::guidance::instructionModifierToString (maneuver.instruction .direction_modifier );
106
-
107
- step_maneuver.values [" location" ] = detail::coordinateToLonLat (maneuver.location );
108
- step_maneuver.values [" bearing_before" ] = detail::roundAndClampBearing (maneuver.bearing_before );
109
- step_maneuver.values [" bearing_after" ] = detail::roundAndClampBearing (maneuver.bearing_after );
106
+ step_maneuver.values .emplace (
107
+ " modifier" ,
108
+ osrm::guidance::instructionModifierToString (maneuver.instruction .direction_modifier ));
109
+
110
+ step_maneuver.values .emplace (" location" , detail::coordinateToLonLat (maneuver.location ));
111
+ step_maneuver.values .emplace (" bearing_before" ,
112
+ detail::roundAndClampBearing (maneuver.bearing_before ));
113
+ step_maneuver.values .emplace (" bearing_after" ,
114
+ detail::roundAndClampBearing (maneuver.bearing_after ));
110
115
if (maneuver.exit != 0 )
111
- step_maneuver.values [ " exit" ] = maneuver.exit ;
116
+ step_maneuver.values . emplace ( " exit" , maneuver.exit ) ;
112
117
113
118
return step_maneuver;
114
119
}
@@ -137,16 +142,16 @@ util::json::Object makeIntersection(const guidance::IntermediateIntersection &in
137
142
return util::json::False ();
138
143
});
139
144
140
- result.values [ " location" ] = detail::coordinateToLonLat (intersection.location );
141
- result.values [ " bearings" ] = bearings;
142
- result.values [ " entry" ] = entry;
145
+ result.values . emplace ( " location" , detail::coordinateToLonLat (intersection.location ) );
146
+ result.values . emplace ( " bearings" , bearings) ;
147
+ result.values . emplace ( " entry" , entry) ;
143
148
if (intersection.in != guidance::IntermediateIntersection::NO_INDEX)
144
- result.values [ " in" ] = intersection.in ;
149
+ result.values . emplace ( " in" , intersection.in ) ;
145
150
if (intersection.out != guidance::IntermediateIntersection::NO_INDEX)
146
- result.values [ " out" ] = intersection.out ;
151
+ result.values . emplace ( " out" , intersection.out ) ;
147
152
148
153
if (detail::hasValidLanes (intersection))
149
- result.values [ " lanes" ] = detail::lanesFromIntersection (intersection);
154
+ result.values . emplace ( " lanes" , detail::lanesFromIntersection (intersection) );
150
155
151
156
if (!intersection.classes .empty ())
152
157
{
@@ -157,7 +162,7 @@ util::json::Object makeIntersection(const guidance::IntermediateIntersection &in
157
162
std::back_inserter (classes.values ),
158
163
[](const std::string &class_name)
159
164
{ return util::json::String{class_name}; });
160
- result.values [ " classes" ] = std::move (classes);
165
+ result.values . emplace ( " classes" , std::move (classes) );
161
166
}
162
167
163
168
return result;
@@ -166,39 +171,44 @@ util::json::Object makeIntersection(const guidance::IntermediateIntersection &in
166
171
util::json::Object makeRouteStep (guidance::RouteStep step, util::json::Value geometry)
167
172
{
168
173
util::json::Object route_step;
169
- route_step.values [" distance" ] = std::round (step.distance * 10 ) / 10 .;
170
- route_step.values [" duration" ] = step.duration ;
171
- route_step.values [" weight" ] = step.weight ;
172
- route_step.values [" name" ] = std::move (step.name );
174
+ route_step.values .reserve (15 );
175
+
176
+ route_step.values .emplace (" distance" , std::round (step.distance * 10 ) / 10 .);
177
+ route_step.values .emplace (" duration" , step.duration );
178
+ route_step.values .emplace (" weight" , step.weight );
179
+ route_step.values .emplace (" name" , step.name );
180
+
173
181
if (!step.ref .empty ())
174
- route_step.values [ " ref" ] = std::move ( step.ref );
182
+ route_step.values . emplace ( " ref" , step.ref );
175
183
if (!step.pronunciation .empty ())
176
- route_step.values [ " pronunciation" ] = std::move ( step.pronunciation );
184
+ route_step.values . emplace ( " pronunciation" , step.pronunciation );
177
185
if (!step.destinations .empty ())
178
- route_step.values [ " destinations" ] = std::move ( step.destinations );
186
+ route_step.values . emplace ( " destinations" , step.destinations );
179
187
if (!step.exits .empty ())
180
- route_step.values [ " exits" ] = std::move ( step.exits );
188
+ route_step.values . emplace ( " exits" , step.exits );
181
189
if (!step.rotary_name .empty ())
182
190
{
183
- route_step.values [ " rotary_name" ] = std::move ( step.rotary_name );
191
+ route_step.values . emplace ( " rotary_name" , step.rotary_name );
184
192
if (!step.rotary_pronunciation .empty ())
185
193
{
186
- route_step.values [ " rotary_pronunciation" ] = std::move ( step.rotary_pronunciation );
194
+ route_step.values . emplace ( " rotary_pronunciation" , step.rotary_pronunciation );
187
195
}
188
196
}
189
197
190
- route_step.values [ " mode" ] = extractor::travelModeToString (step.mode );
191
- route_step.values [ " maneuver" ] = makeStepManeuver (step.maneuver );
192
- route_step.values [ " geometry" ] = std::move (geometry);
193
- route_step.values [ " driving_side" ] = step.is_left_hand_driving ? " left" : " right" ;
198
+ route_step.values . emplace ( " mode" , extractor::travelModeToString (step.mode ) );
199
+ route_step.values . emplace ( " maneuver" , makeStepManeuver (step.maneuver ) );
200
+ route_step.values . emplace ( " geometry" , std::move (geometry) );
201
+ route_step.values . emplace ( " driving_side" , step.is_left_hand_driving ? " left" : " right" ) ;
194
202
195
203
util::json::Array intersections;
196
204
intersections.values .reserve (step.intersections .size ());
205
+
197
206
std::transform (step.intersections .begin (),
198
207
step.intersections .end (),
199
208
std::back_inserter (intersections.values ),
200
209
makeIntersection);
201
- route_step.values [" intersections" ] = std::move (intersections);
210
+
211
+ route_step.values .emplace (" intersections" , std::move (intersections));
202
212
203
213
return route_step;
204
214
}
@@ -209,14 +219,16 @@ util::json::Object makeRoute(const guidance::Route &route,
209
219
const char *weight_name)
210
220
{
211
221
util::json::Object json_route;
212
- json_route.values [" distance" ] = route.distance ;
213
- json_route.values [" duration" ] = route.duration ;
214
- json_route.values [" weight" ] = route.weight ;
215
- json_route.values [" weight_name" ] = weight_name;
216
- json_route.values [" legs" ] = std::move (legs);
222
+ json_route.values .reserve (6 );
223
+
224
+ json_route.values .emplace (" distance" , route.distance );
225
+ json_route.values .emplace (" duration" , route.duration );
226
+ json_route.values .emplace (" weight" , route.weight );
227
+ json_route.values .emplace (" weight_name" , weight_name);
228
+ json_route.values .emplace (" legs" , std::move (legs));
217
229
if (geometry)
218
230
{
219
- json_route.values [ " geometry" ] = *std::move (geometry);
231
+ json_route.values . emplace ( " geometry" , *std::move (geometry) );
220
232
}
221
233
return json_route;
222
234
}
@@ -225,9 +237,11 @@ util::json::Object
225
237
makeWaypoint (const util::Coordinate &location, const double &distance, std::string name)
226
238
{
227
239
util::json::Object waypoint;
228
- waypoint.values [" location" ] = detail::coordinateToLonLat (location);
229
- waypoint.values [" name" ] = std::move (name);
230
- waypoint.values [" distance" ] = distance;
240
+ waypoint.values .reserve (3 );
241
+
242
+ waypoint.values .emplace (" location" , detail::coordinateToLonLat (location));
243
+ waypoint.values .emplace (" name" , std::move (name));
244
+ waypoint.values .emplace (" distance" , distance);
231
245
return waypoint;
232
246
}
233
247
@@ -237,26 +251,29 @@ util::json::Object makeWaypoint(const util::Coordinate &location,
237
251
const Hint &location_hints)
238
252
{
239
253
auto waypoint = makeWaypoint (location, distance, std::move (name));
240
- waypoint.values [" hint" ] = location_hints.ToBase64 ();
254
+ waypoint.values .reserve (1 );
255
+ waypoint.values .emplace (" hint" , location_hints.ToBase64 ());
241
256
return waypoint;
242
257
}
243
258
244
259
util::json::Object makeRouteLeg (guidance::RouteLeg leg, util::json::Array steps)
245
260
{
246
261
util::json::Object route_leg;
247
- route_leg.values [" distance" ] = leg.distance ;
248
- route_leg.values [" duration" ] = leg.duration ;
249
- route_leg.values [" weight" ] = leg.weight ;
250
- route_leg.values [" summary" ] = std::move (leg.summary );
251
- route_leg.values [" steps" ] = std::move (steps);
262
+ route_leg.values .reserve (5 );
263
+
264
+ route_leg.values .emplace (" distance" , leg.distance );
265
+ route_leg.values .emplace (" duration" , leg.duration );
266
+ route_leg.values .emplace (" weight" , leg.weight );
267
+ route_leg.values .emplace (" summary" , std::move (leg.summary ));
268
+ route_leg.values .emplace (" steps" , std::move (steps));
252
269
return route_leg;
253
270
}
254
-
255
271
util::json::Object
256
272
makeRouteLeg (guidance::RouteLeg leg, util::json::Array steps, util::json::Object annotation)
257
273
{
258
274
util::json::Object route_leg = makeRouteLeg (std::move (leg), std::move (steps));
259
- route_leg.values [" annotation" ] = std::move (annotation);
275
+ route_leg.values .reserve (1 );
276
+ route_leg.values .emplace (" annotation" , std::move (annotation));
260
277
return route_leg;
261
278
}
262
279
0 commit comments