diff --git a/NEWS b/NEWS index 45062c3d845..ec6072273e0 100644 --- a/NEWS +++ b/NEWS @@ -32,6 +32,8 @@ milestone for 3.3.2 edgeDisjointPaths issues with start_vid and combinations * [#2312](https://github.com/pgRouting/pgrouting/issues/2312): pgr_extractVertices error when target is not BIGINT +* [#2357](https://github.com/pgRouting/pgrouting/issues/2357): + Apply clang-tidy performance-* pgRouting 3.3.1 Release Notes ------------------------------------------------------------------------------- diff --git a/doc/src/pgRouting-introduction.rst b/doc/src/pgRouting-introduction.rst index 6fafd14aaa7..fc73da737aa 100644 --- a/doc/src/pgRouting-introduction.rst +++ b/doc/src/pgRouting-introduction.rst @@ -83,6 +83,7 @@ Individuals in this release (in alphabetical order) Ashish Kumar, Cayetano Benavent, Daniel Kastl, +Loïc Bartoletti, Rajat Shinde, Regina Obe, Swapnil Joshi, @@ -139,6 +140,7 @@ Jinfu Leng, Kai Behncke, Kishore Kumar, Ko Nagase, +Loïc Bartoletti, Mahmoud Sakr, Manikata Kondeti, Mario Basa, diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index f429be92c4b..06f08c68ec9 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -69,6 +69,8 @@ milestone for 3.3.2 edgeDisjointPaths issues with start_vid and combinations * `#2312 `__: pgr_extractVertices error when target is not BIGINT +* `#2357 `__: + Apply clang-tidy performance-* pgRouting 3.3.1 Release Notes ------------------------------------------------------------------------------- diff --git a/include/alphaShape/pgr_alphaShape.h b/include/alphaShape/pgr_alphaShape.h index 066b72121eb..4d8a890fa85 100644 --- a/include/alphaShape/pgr_alphaShape.h +++ b/include/alphaShape/pgr_alphaShape.h @@ -71,12 +71,12 @@ class Pgr_alphaShape : public Pgr_messages { private: void make_triangles(); - double radius(const Triangle t) const; + double radius(const Triangle& t) const; bool faceBelongs( - const Triangle face, + const Triangle& face, double alpha) const; void recursive_build( - const Triangle face, + const Triangle& face, std::set &used, std::set &border_edges, double alpha) const; diff --git a/include/cpp_common/basic_vertex.h b/include/cpp_common/basic_vertex.h index 6a226090fd1..6b114c0d79c 100644 --- a/include/cpp_common/basic_vertex.h +++ b/include/cpp_common/basic_vertex.h @@ -72,7 +72,7 @@ std::vector < Basic_vertex > extract_vertices( std::vector < Basic_vertex > extract_vertices( std::vector < Basic_vertex > vertices, - const std::vector < Edge_t > data_edges); + const std::vector < Edge_t >& data_edges); std::vector < Basic_vertex > extract_vertices( const Edge_t *data_edges, size_t count); diff --git a/include/spanningTree/details.hpp b/include/spanningTree/details.hpp index 5027cea4bc0..cd272f91e00 100644 --- a/include/spanningTree/details.hpp +++ b/include/spanningTree/details.hpp @@ -38,7 +38,7 @@ clean_vids(std::vector vids); std::vector get_no_edge_graph_result( - std::vector vids); + const std::vector& vids); } // namespace details } // namespace pgrouting diff --git a/include/trsp/pgr_trspHandler.h b/include/trsp/pgr_trspHandler.h index 6862aed9484..f5ac8c9b662 100644 --- a/include/trsp/pgr_trspHandler.h +++ b/include/trsp/pgr_trspHandler.h @@ -120,8 +120,8 @@ class Pgr_trspHandler { std::set> &combinations); std::deque process( - const std::vector sources, - const std::vector targets); + const std::vector& sources, + const std::vector& targets); void clear(); @@ -149,7 +149,7 @@ class Pgr_trspHandler { void explore( int64_t cur_node, - const EdgeInfo cur_edge, + const EdgeInfo& cur_edge, bool isStart); double getRestrictionCost( diff --git a/include/vrp/optimize.h b/include/vrp/optimize.h index 5fb67ee5baa..47c89372d78 100644 --- a/include/vrp/optimize.h +++ b/include/vrp/optimize.h @@ -62,7 +62,7 @@ class Optimize : public Solution { bool inter_swap(); bool move_order( - Order order, + const Order& order, Vehicle_pickDeliver &from_truck, Vehicle_pickDeliver &to_truck); void save_if_best(); diff --git a/include/vrp/order.h b/include/vrp/order.h index 5944cb855c0..9ceb10ed71b 100644 --- a/include/vrp/order.h +++ b/include/vrp/order.h @@ -91,7 +91,7 @@ class Order : public Identifier { * @{ */ - void set_compatibles(const Order order, double speed); + void set_compatibles(const Order& order, double speed); /*!@}*/ /*! @name To be or not to be diff --git a/include/vrp/vehicle.h b/include/vrp/vehicle.h index 9f079cd6b3a..ef4975c5728 100644 --- a/include/vrp/vehicle.h +++ b/include/vrp/vehicle.h @@ -143,7 +143,7 @@ class Vehicle : public Identifier { * * @returns position where it was inserted */ - POS insert(std::pair position_limits, const Vehicle_node &node); + POS insert(const std::pair& position_limits, const Vehicle_node &node); diff --git a/include/withPoints/pgr_withPoints.hpp b/include/withPoints/pgr_withPoints.hpp index 7a26c343d53..fb3e99f032a 100644 --- a/include/withPoints/pgr_withPoints.hpp +++ b/include/withPoints/pgr_withPoints.hpp @@ -49,7 +49,7 @@ class Pg_points_graph : public Pgr_messages { Pg_points_graph() = delete; Pg_points_graph(const Pg_points_graph &) = delete; Pg_points_graph( - std::vector p_points, + const std::vector& p_points, std::vector p_edges_to_modify, bool p_normal, char p_driving_side, @@ -62,7 +62,7 @@ class Pg_points_graph : public Pgr_messages { Path eliminate_details( - Path path) const; + const Path& path) const; void eliminate_details_dd( Path &path) const; diff --git a/src/alpha_shape/pgr_alphaShape.cpp b/src/alpha_shape/pgr_alphaShape.cpp index e87e6a357e5..ef94985be3e 100644 --- a/src/alpha_shape/pgr_alphaShape.cpp +++ b/src/alpha_shape/pgr_alphaShape.cpp @@ -224,7 +224,7 @@ Pgr_alphaShape::make_triangles() { * Radius of triangle's circumcenter */ double -Pgr_alphaShape::radius(const Triangle t) const { +Pgr_alphaShape::radius(const Triangle& t) const { std::vector edges(t.begin(), t.end()); auto a = graph.source(edges[0]); auto b = graph.target(edges[0]); @@ -240,7 +240,7 @@ Pgr_alphaShape::radius(const Triangle t) const { * The whole traingle face belongs to the shape? */ bool -Pgr_alphaShape::faceBelongs(const Triangle t, double alpha) const { +Pgr_alphaShape::faceBelongs(const Triangle& t, double alpha) const { return radius(t) <= alpha; } @@ -317,7 +317,7 @@ Pgr_alphaShape::build_best_alpha() const { void Pgr_alphaShape::recursive_build( - const Triangle face, + const Triangle& face, std::set &used, std::set &border_edges, double alpha) const { diff --git a/src/common/basic_vertex.cpp b/src/common/basic_vertex.cpp index 1259069cbb6..ec3fa97cf48 100644 --- a/src/common/basic_vertex.cpp +++ b/src/common/basic_vertex.cpp @@ -58,7 +58,7 @@ namespace pgrouting { std::vector < Basic_vertex > extract_vertices( std::vector < Basic_vertex > vertices, - std::vector data_edges) { + const std::vector & data_edges) { if (data_edges.empty()) return vertices; vertices.reserve(vertices.size() + data_edges.size() * 2); diff --git a/src/common/pgr_assert.cpp b/src/common/pgr_assert.cpp index 7a6a41090cc..e6869a2d863 100644 --- a/src/common/pgr_assert.cpp +++ b/src/common/pgr_assert.cpp @@ -33,8 +33,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #endif -#include #include +#include +#include std::string get_backtrace() { @@ -69,5 +70,5 @@ const char* AssertFailedException::what() const throw() { } AssertFailedException::AssertFailedException(std::string msg) : - str(msg) {} + str(std::move(msg)) {} diff --git a/src/cpp_common/Dmatrix.cpp b/src/cpp_common/Dmatrix.cpp index a236689a7b7..f7d30eeb05b 100644 --- a/src/cpp_common/Dmatrix.cpp +++ b/src/cpp_common/Dmatrix.cpp @@ -105,7 +105,7 @@ Dmatrix::Dmatrix(const std::vector < IID_t_rt > &data_costs) { double -get_distance(std::pair p1 , std::pair p2) { +get_distance(const std::pair& p1 , const std::pair& p2) { auto dx = p1.first - p2.first; auto dy = p1.second - p2.second; return std::sqrt(dx * dx + dy * dy); diff --git a/src/lineGraph/lineGraphFull_driver.cpp b/src/lineGraph/lineGraphFull_driver.cpp index f7d65ee8b94..5750a8f3b6d 100644 --- a/src/lineGraph/lineGraphFull_driver.cpp +++ b/src/lineGraph/lineGraphFull_driver.cpp @@ -43,7 +43,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "cpp_common/linear_directed_graph.h" void get_turn_penalty_postgres_result( - std::vector< Line_graph_full_rt > edge_result, + const std::vector< Line_graph_full_rt >& edge_result, Line_graph_full_rt **return_tuples, size_t &sequence) { (*return_tuples) = pgr_alloc(edge_result.size(), (*return_tuples)); diff --git a/src/lineGraph/lineGraph_driver.cpp b/src/lineGraph/lineGraph_driver.cpp index 9f9e067a145..4ccfd9b33c8 100644 --- a/src/lineGraph/lineGraph_driver.cpp +++ b/src/lineGraph/lineGraph_driver.cpp @@ -44,7 +44,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. void get_postgres_result( - std::vector< Edge_t > edge_result, + const std::vector< Edge_t >& edge_result, Edge_t **return_tuples, size_t &sequence) { (*return_tuples) = pgr_alloc(edge_result.size(), (*return_tuples)); diff --git a/src/max_flow/edge_disjoint_paths_driver.cpp b/src/max_flow/edge_disjoint_paths_driver.cpp index 0fc44edbc4d..56ff113252a 100644 --- a/src/max_flow/edge_disjoint_paths_driver.cpp +++ b/src/max_flow/edge_disjoint_paths_driver.cpp @@ -75,7 +75,7 @@ get_combinations( static std::vector single_execution( - std::vector edges, + const std::vector& edges, int64_t source, int64_t target, bool directed) { diff --git a/src/pickDeliver/fleet.cpp b/src/pickDeliver/fleet.cpp index ea97e839070..0187c3b5708 100644 --- a/src/pickDeliver/fleet.cpp +++ b/src/pickDeliver/fleet.cpp @@ -103,7 +103,7 @@ Fleet::get_truck(size_t order) { pgassert(false); return m_trucks.back(); - for (auto truck : m_trucks) { + for (const auto& truck : m_trucks) { if (truck.feasable_orders().has(order)) { idx = truck.idx(); msg().log << "idx" << idx << "size" << m_trucks.size(); @@ -254,7 +254,7 @@ bool Fleet::is_fleet_ok() const { ENTERING(msg()); if (!msg().get_error().empty()) return false; - for (auto truck : m_trucks) { + for (const auto& truck : m_trucks) { if (!truck.is_ok()) { msg().error << "Illegal values found on vehicle"; msg().log << "On vehicle " << truck.id() diff --git a/src/pickDeliver/optimize.cpp b/src/pickDeliver/optimize.cpp index 8821786cfd2..4937e9befb2 100644 --- a/src/pickDeliver/optimize.cpp +++ b/src/pickDeliver/optimize.cpp @@ -391,7 +391,7 @@ Optimize::move_reduce_cost( */ bool Optimize::move_order( - Order order, + const Order& order, Vehicle_pickDeliver &from_truck, Vehicle_pickDeliver &to_truck) { pgassert(from_truck.has_order(order)); diff --git a/src/pickDeliver/order.cpp b/src/pickDeliver/order.cpp index 61e32264304..b2da19da663 100644 --- a/src/pickDeliver/order.cpp +++ b/src/pickDeliver/order.cpp @@ -108,7 +108,7 @@ Order::is_valid(double speed) const { * */ void -Order::set_compatibles(const Order J, double speed) { +Order::set_compatibles(const Order& J, double speed) { if (J.idx() == idx()) return; if (J.isCompatibleIJ(*this, speed)) { /* diff --git a/src/pickDeliver/vehicle.cpp b/src/pickDeliver/vehicle.cpp index 88162551f9f..2f98718b280 100644 --- a/src/pickDeliver/vehicle.cpp +++ b/src/pickDeliver/vehicle.cpp @@ -62,7 +62,7 @@ Vehicle::invariant() const { } size_t -Vehicle::insert(std::pair position_limits, const Vehicle_node &node) { +Vehicle::insert(const std::pair& position_limits, const Vehicle_node &node) { invariant(); pgassert(position_limits.first <= m_path.size()); pgassert(position_limits.second <= m_path.size()); diff --git a/src/spanningTree/details.cpp b/src/spanningTree/details.cpp index dd824a5be8d..be386b01056 100644 --- a/src/spanningTree/details.cpp +++ b/src/spanningTree/details.cpp @@ -43,7 +43,7 @@ clean_vids(std::vector vids) { std::vector get_no_edge_graph_result( - std::vector vids) { + const std::vector& vids) { std::vector results; if (vids.empty()) return results; for (auto const root : clean_vids(vids)) { diff --git a/src/trsp/pgr_trspHandler.cpp b/src/trsp/pgr_trspHandler.cpp index 04ed4d3a931..62ae2f76bf7 100644 --- a/src/trsp/pgr_trspHandler.cpp +++ b/src/trsp/pgr_trspHandler.cpp @@ -219,7 +219,7 @@ double Pgr_trspHandler::get_tot_cost( // ------------------------------------------------------------------------- void Pgr_trspHandler::explore( int64_t cur_node, - const EdgeInfo cur_edge, + const EdgeInfo& cur_edge, bool isStart) { double totalCost; @@ -342,8 +342,8 @@ Pgr_trspHandler::process( */ std::deque Pgr_trspHandler::process( - const std::vector sources, - const std::vector targets) { + const std::vector& sources, + const std::vector& targets) { std::deque paths; for (const auto &s : sources) { for (const auto &t : targets) { diff --git a/src/withPoints/pgr_withPoints.cpp b/src/withPoints/pgr_withPoints.cpp index c888ebaf37c..7aab0885052 100644 --- a/src/withPoints/pgr_withPoints.cpp +++ b/src/withPoints/pgr_withPoints.cpp @@ -30,13 +30,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "withPoints/pgr_withPoints.hpp" -#include +#include +#include #include #include -#include +#include #include -#include -#include +#include +#include #include "cpp_common/pgr_assert.h" @@ -69,14 +70,14 @@ Pg_points_graph::edges_of_points() const { Pg_points_graph::Pg_points_graph( - std::vector p_points, + const std::vector& p_points, std::vector p_edges_of_points, bool p_normal, char p_driving_side, bool p_directed) : m_points(p_points), m_o_points(p_points), - m_edges_of_points(p_edges_of_points), + m_edges_of_points(std::move(p_edges_of_points)), m_driving_side(p_driving_side), m_directed(p_directed) { if (!p_normal) { @@ -227,7 +228,7 @@ Pg_points_graph::eliminate_details_dd( Path Pg_points_graph::eliminate_details( - Path path) const { + const Path& path) const { /* * There is no path nothing to do */