From ee178b2d3a25a06af908b0ef722eab4107d62d22 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 14 Nov 2019 15:59:59 +0100 Subject: [PATCH] Avoid a number of temporaries --- src/customize/customizer.cpp | 2 +- src/engine/api/json_factory.cpp | 2 +- src/extractor/extractor.cpp | 6 +++--- src/guidance/segregated_intersection_classification.cpp | 4 ++-- src/guidance/turn_lane_data.cpp | 2 +- src/updater/updater.cpp | 2 +- unit_tests/engine/geometry_string.cpp | 2 +- unit_tests/library/json.cpp | 8 ++++---- unit_tests/library/route.cpp | 2 +- unit_tests/partitioner/recursive_bisection.cpp | 2 +- unit_tests/util/range_table.cpp | 2 +- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/customize/customizer.cpp b/src/customize/customizer.cpp index d7e2af90d..0c6f105b3 100644 --- a/src/customize/customizer.cpp +++ b/src/customize/customizer.cpp @@ -105,7 +105,7 @@ std::vector customizeFilteredMetrics(const partitioner::MultiLevelEd { std::vector metrics; - for (auto filter : node_filters) + for (const auto& filter : node_filters) { auto metric = storage.MakeMetric(); customizer.Customize(graph, storage, filter, metric); diff --git a/src/engine/api/json_factory.cpp b/src/engine/api/json_factory.cpp index 8df45c94c..b8553d883 100644 --- a/src/engine/api/json_factory.cpp +++ b/src/engine/api/json_factory.cpp @@ -242,7 +242,7 @@ util::json::Object makeWaypoint(const util::Coordinate &location, std::string name, const Hint &hint) { - auto waypoint = makeWaypoint(location, distance, name); + auto waypoint = makeWaypoint(location, distance, std::move(name)); waypoint.values["hint"] = hint.ToBase64(); return waypoint; } diff --git a/src/extractor/extractor.cpp b/src/extractor/extractor.cpp index 36f137293..54e2c4ffe 100644 --- a/src/extractor/extractor.cpp +++ b/src/extractor/extractor.cpp @@ -509,7 +509,7 @@ Extractor::ParseOSMData(ScriptingEnvironment &scripting_environment, // OSM elements Lua parser tbb::filter_t buffer_transformer( - tbb::filter::parallel, [&](const SharedBuffer buffer) { + tbb::filter::parallel, [&](const SharedBuffer& buffer) { ParsedBuffer parsed_buffer; parsed_buffer.buffer = buffer; @@ -559,7 +559,7 @@ Extractor::ParseOSMData(ScriptingEnvironment &scripting_environment, }); tbb::filter_t> buffer_relation_cache( - tbb::filter::parallel, [&](const SharedBuffer buffer) { + tbb::filter::parallel, [&](const SharedBuffer& buffer) { if (!buffer) return std::shared_ptr{}; @@ -596,7 +596,7 @@ Extractor::ParseOSMData(ScriptingEnvironment &scripting_environment, unsigned number_of_relations = 0; tbb::filter_t, void> buffer_storage_relation( tbb::filter::serial_in_order, - [&](const std::shared_ptr parsed_relations) { + [&](const std::shared_ptr &parsed_relations) { number_of_relations += parsed_relations->GetRelationsNum(); relations.Merge(std::move(*parsed_relations)); diff --git a/src/guidance/segregated_intersection_classification.cpp b/src/guidance/segregated_intersection_classification.cpp index d8aaadafd..34abce291 100644 --- a/src/guidance/segregated_intersection_classification.cpp +++ b/src/guidance/segregated_intersection_classification.cpp @@ -109,8 +109,8 @@ std::unordered_set findSegregatedNodes(const extractor::NodeBasedGraphFa }; auto isSegregated = [&](NodeID node1, - std::vector v1, - std::vector v2, + const std::vector &v1, + const std::vector &v2, EdgeInfo const ¤t, double edge_length) { // Internal intersection edges must be short and cannot be a roundabout. diff --git a/src/guidance/turn_lane_data.cpp b/src/guidance/turn_lane_data.cpp index 409d2e613..c983c5de2 100644 --- a/src/guidance/turn_lane_data.cpp +++ b/src/guidance/turn_lane_data.cpp @@ -64,7 +64,7 @@ bool TurnLaneData::operator<(const TurnLaneData &other) const std::find(tag_by_modifier, tag_by_modifier + 8, other.tag); } -LaneDataVector laneDataFromDescription(TurnLaneDescription turn_lane_description) +LaneDataVector laneDataFromDescription(const TurnLaneDescription& turn_lane_description) { typedef std::unordered_map> LaneMap; // TODO need to handle cases that have none-in between two identical values diff --git a/src/updater/updater.cpp b/src/updater/updater.cpp index f4dc902a3..c46fc0b70 100644 --- a/src/updater/updater.cpp +++ b/src/updater/updater.cpp @@ -507,7 +507,7 @@ bool IsRestrictionValid(const Timezoner &tz_handler, const extractor::Conditiona std::vector updateConditionalTurns(std::vector &turn_weight_penalties, const std::vector &conditional_turns, - Timezoner time_zone_handler) + const Timezoner& time_zone_handler) { std::vector updated_turns; if (conditional_turns.size() == 0) diff --git a/unit_tests/engine/geometry_string.cpp b/unit_tests/engine/geometry_string.cpp index 27727c2ca..dd7a2b47f 100644 --- a/unit_tests/engine/geometry_string.cpp +++ b/unit_tests/engine/geometry_string.cpp @@ -135,7 +135,7 @@ BOOST_AUTO_TEST_CASE(incorrect_polylines) }; util::Coordinate coord{util::FloatLongitude{0}, util::FloatLatitude{0}}; - for (auto polyline : polylines) + for (const auto& polyline : polylines) { const auto result = decodePolyline(polyline); BOOST_CHECK(result.size() == 1); diff --git a/unit_tests/library/json.cpp b/unit_tests/library/json.cpp index 645acd396..a2ea46db5 100644 --- a/unit_tests/library/json.cpp +++ b/unit_tests/library/json.cpp @@ -28,7 +28,7 @@ BOOST_AUTO_TEST_CASE(test_json_linestring) const auto coords = geom.values["coordinates"].get().values; BOOST_CHECK_EQUAL(coords.size(), 3); // array of three location arrays - for (const auto each : coords) + for (const auto& each : coords) { const auto loc = each.get().values; BOOST_CHECK_EQUAL(loc.size(), 2); @@ -38,7 +38,7 @@ BOOST_AUTO_TEST_CASE(test_json_linestring) (void)lon; (void)lat; - // cast fails if type do not match + // cast fails if types do not match } } @@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(test_json_single_point) const auto coords = geom.values["coordinates"].get().values; BOOST_CHECK_EQUAL(coords.size(), 2); // array of two location arrays - for (const auto each : coords) + for (const auto& each : coords) { const auto loc = each.get().values; BOOST_CHECK_EQUAL(loc.size(), 2); @@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(test_json_single_point) (void)lon; (void)lat; - // cast fails if type do not match + // cast fails if types do not match } } diff --git a/unit_tests/library/route.cpp b/unit_tests/library/route.cpp index a2984530b..669b99654 100644 --- a/unit_tests/library/route.cpp +++ b/unit_tests/library/route.cpp @@ -243,7 +243,7 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates) const auto &entries = intersection_object.at("entry").get().values; BOOST_CHECK(bearings.size() == entries.size()); - for (const auto bearing : bearings) + for (const auto& bearing : bearings) BOOST_CHECK(0. <= bearing.get().value && bearing.get().value <= 360.); diff --git a/unit_tests/partitioner/recursive_bisection.cpp b/unit_tests/partitioner/recursive_bisection.cpp index 1c911efaf..1ff356b9f 100644 --- a/unit_tests/partitioner/recursive_bisection.cpp +++ b/unit_tests/partitioner/recursive_bisection.cpp @@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE(dividing_four_grid_cells) RecursiveBisection bisection(graph, 120, 1.1, 0.25, 10, 1); - const auto result = bisection.BisectionIDs(); + const auto& result = bisection.BisectionIDs(); // all same IDs withing a group for (int i = 0; i < 4; ++i) for (int j = 0; j < rows * cols; ++j) diff --git a/unit_tests/util/range_table.cpp b/unit_tests/util/range_table.cpp index f1d0cecac..3f769cbb3 100644 --- a/unit_tests/util/range_table.cpp +++ b/unit_tests/util/range_table.cpp @@ -15,7 +15,7 @@ using namespace osrm::util; constexpr unsigned BLOCK_SIZE = 16; typedef RangeTable TestRangeTable; -void ConstructionTest(std::vector lengths, std::vector offsets) +void ConstructionTest(const std::vector& lengths, const std::vector& offsets) { BOOST_CHECK_EQUAL(lengths.size(), offsets.size() - 1);