Skip to content

Commit 58ba3fc

Browse files
authored
Avoid copying ManyToMany table results (#5923)
Regardless of any copy elision on the returned pair value, the duration and distance results are always copied. Fix this by passing rvalue references to std::make_pair.
1 parent dddf83d commit 58ba3fc

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
- ADDED: Added support for multiple via-way restrictions. [#5907](https://github.com/Project-OSRM/osrm-backend/pull/5907)
55
- ADDED: Add node bindings support for Node 12, 14, and publish binaries [#5918](https://github.com/Project-OSRM/osrm-backend/pull/5918)
66
- REMOVED: we no longer publish Node 8 binary modules (they are still buildable from source) [#5918](https://github.com/Project-OSRM/osrm-backend/pull/5918)
7+
- Routing:
8+
- FIXED: Avoid copying ManyToMany table results [#5923](https://github.com/Project-OSRM/osrm-backend/pull/5923)
79
- Misc:
810
- CHANGED: Unify `.osrm.turn_penalites_index` dump processing same with `.osrm.turn_weight_penalties` and `.osrm.turn_duration_penalties` [#5868](https://github.com/Project-OSRM/osrm-backend/pull/5868)
911
- Profile:

src/engine/routing_algorithms/many_to_many_ch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ manyToManySearch(SearchEngineData<ch::Algorithm> &engine_working_data,
248248
}
249249
}
250250

251-
return std::make_pair(durations_table, distances_table);
251+
return std::make_pair(std::move(durations_table), std::move(distances_table));
252252
}
253253

254254
} // namespace routing_algorithms

src/engine/routing_algorithms/many_to_many_mld.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ oneToManySearch(SearchEngineData<Algorithm> &engine_working_data,
219219
const std::vector<std::size_t> &phantom_indices,
220220
const bool calculate_distance)
221221
{
222-
std::vector<EdgeWeight> weights(phantom_indices.size(), INVALID_EDGE_WEIGHT);
223-
std::vector<EdgeDuration> durations(phantom_indices.size(), MAXIMAL_EDGE_DURATION);
222+
std::vector<EdgeWeight> weights_table(phantom_indices.size(), INVALID_EDGE_WEIGHT);
223+
std::vector<EdgeDuration> durations_table(phantom_indices.size(), MAXIMAL_EDGE_DURATION);
224224
std::vector<EdgeDistance> distances_table(calculate_distance ? phantom_indices.size() : 0,
225225
MAXIMAL_EDGE_DISTANCE);
226226
std::vector<NodeID> middle_nodes_table(phantom_indices.size(), SPECIAL_NODEID);
@@ -298,10 +298,10 @@ oneToManySearch(SearchEngineData<Algorithm> &engine_working_data,
298298
distances_table.empty() ? nulldistance : distances_table[index];
299299

300300
if (std::tie(path_weight, path_duration, path_distance) <
301-
std::tie(weights[index], durations[index], current_distance))
301+
std::tie(weights_table[index], durations_table[index], current_distance))
302302
{
303-
weights[index] = path_weight;
304-
durations[index] = path_duration;
303+
weights_table[index] = path_weight;
304+
durations_table[index] = path_duration;
305305
current_distance = path_distance;
306306
middle_nodes_table[index] = node;
307307
}
@@ -392,7 +392,7 @@ oneToManySearch(SearchEngineData<Algorithm> &engine_working_data,
392392
facade, heapNode, query_heap, phantom_nodes, phantom_index, phantom_indices);
393393
}
394394

395-
return std::make_pair(durations, distances_table);
395+
return std::make_pair(std::move(durations_table), std::move(distances_table));
396396
}
397397

398398
//
@@ -601,7 +601,7 @@ manyToManySearch(SearchEngineData<Algorithm> &engine_working_data,
601601
}
602602
}
603603

604-
return std::make_pair(durations_table, distances_table);
604+
return std::make_pair(std::move(durations_table), std::move(distances_table));
605605
}
606606

607607
} // namespace mld

0 commit comments

Comments
 (0)