Skip to content

Commit

Permalink
Clang tidy perf (#2356)
Browse files Browse the repository at this point in the history
* Apply clang-tidy performance-*
* Add myself to the contributors list
* Mention the issue in release notes
  • Loading branch information
lbartoletti authored Aug 21, 2022
1 parent 2721bee commit 003b144
Show file tree
Hide file tree
Showing 25 changed files with 47 additions and 39 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions doc/src/pgRouting-introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -139,6 +140,7 @@ Jinfu Leng,
Kai Behncke,
Kishore Kumar,
Ko Nagase,
Loïc Bartoletti,
Mahmoud Sakr,
Manikata Kondeti,
Mario Basa,
Expand Down
2 changes: 2 additions & 0 deletions doc/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,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
-------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions include/alphaShape/pgr_alphaShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Triangle> &used,
std::set<E> &border_edges,
double alpha) const;
Expand Down
2 changes: 1 addition & 1 deletion include/cpp_common/basic_vertex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/spanningTree/details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ clean_vids(std::vector<int64_t> vids);

std::vector<MST_rt>
get_no_edge_graph_result(
std::vector<int64_t> vids);
const std::vector<int64_t>& vids);

} // namespace details
} // namespace pgrouting
Expand Down
6 changes: 3 additions & 3 deletions include/trsp/pgr_trspHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class Pgr_trspHandler {
std::set<int64_t>> &combinations);

std::deque<Path> process(
const std::vector<int64_t> sources,
const std::vector<int64_t> targets);
const std::vector<int64_t>& sources,
const std::vector<int64_t>& targets);


void clear();
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion include/vrp/optimize.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion include/vrp/order.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/vrp/vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class Vehicle : public Identifier {
*
* @returns position where it was inserted
*/
POS insert(std::pair<POS, POS> position_limits, const Vehicle_node &node);
POS insert(const std::pair<POS, POS>& position_limits, const Vehicle_node &node);



Expand Down
4 changes: 2 additions & 2 deletions include/withPoints/pgr_withPoints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Point_on_edge_t> p_points,
const std::vector<Point_on_edge_t>& p_points,
std::vector<Edge_t> p_edges_to_modify,
bool p_normal,
char p_driving_side,
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/alpha_shape/pgr_alphaShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<E> edges(t.begin(), t.end());
auto a = graph.source(edges[0]);
auto b = graph.target(edges[0]);
Expand All @@ -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;
}

Expand Down Expand Up @@ -317,7 +317,7 @@ Pgr_alphaShape::build_best_alpha() const {

void
Pgr_alphaShape::recursive_build(
const Triangle face,
const Triangle& face,
std::set<Triangle> &used,
std::set<E> &border_edges,
double alpha) const {
Expand Down
2 changes: 1 addition & 1 deletion src/common/basic_vertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace pgrouting {

std::vector < Basic_vertex > extract_vertices(
std::vector < Basic_vertex > vertices,
std::vector <Edge_t> data_edges) {
const std::vector <Edge_t>& data_edges) {
if (data_edges.empty()) return vertices;

vertices.reserve(vertices.size() + data_edges.size() * 2);
Expand Down
5 changes: 3 additions & 2 deletions src/common/pgr_assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <execinfo.h>
#endif

#include <string>
#include <exception>
#include <string>
#include <utility>


std::string get_backtrace() {
Expand Down Expand Up @@ -69,5 +70,5 @@ const char* AssertFailedException::what() const throw() {
}

AssertFailedException::AssertFailedException(std::string msg) :
str(msg) {}
str(std::move(msg)) {}

2 changes: 1 addition & 1 deletion src/cpp_common/Dmatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Dmatrix::Dmatrix(const std::vector < IID_t_rt > &data_costs) {


double
get_distance(std::pair<double, double> p1 , std::pair<double, double> p2) {
get_distance(const std::pair<double, double>& p1 , const std::pair<double, double>& p2) {
auto dx = p1.first - p2.first;
auto dy = p1.second - p2.second;
return std::sqrt(dx * dx + dy * dy);
Expand Down
2 changes: 1 addition & 1 deletion src/lineGraph/lineGraphFull_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/lineGraph/lineGraph_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/max_flow/edge_disjoint_paths_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ get_combinations(
static
std::vector<Path_rt>
single_execution(
std::vector<Edge_t> edges,
const std::vector<Edge_t>& edges,
int64_t source,
int64_t target,
bool directed) {
Expand Down
4 changes: 2 additions & 2 deletions src/pickDeliver/fleet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/pickDeliver/optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/pickDeliver/order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
/*
Expand Down
2 changes: 1 addition & 1 deletion src/pickDeliver/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Vehicle::invariant() const {
}

size_t
Vehicle::insert(std::pair<POS, POS> position_limits, const Vehicle_node &node) {
Vehicle::insert(const std::pair<POS, POS>& position_limits, const Vehicle_node &node) {
invariant();
pgassert(position_limits.first <= m_path.size());
pgassert(position_limits.second <= m_path.size());
Expand Down
2 changes: 1 addition & 1 deletion src/spanningTree/details.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ clean_vids(std::vector<int64_t> vids) {

std::vector<MST_rt>
get_no_edge_graph_result(
std::vector<int64_t> vids) {
const std::vector<int64_t>& vids) {
std::vector<MST_rt> results;
if (vids.empty()) return results;
for (auto const root : clean_vids(vids)) {
Expand Down
6 changes: 3 additions & 3 deletions src/trsp/pgr_trspHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -342,8 +342,8 @@ Pgr_trspHandler::process(
*/
std::deque<Path>
Pgr_trspHandler::process(
const std::vector<int64_t> sources,
const std::vector<int64_t> targets) {
const std::vector<int64_t>& sources,
const std::vector<int64_t>& targets) {
std::deque<Path> paths;
for (const auto &s : sources) {
for (const auto &t : targets) {
Expand Down
15 changes: 8 additions & 7 deletions src/withPoints/pgr_withPoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include "withPoints/pgr_withPoints.hpp"

#include <sstream>
#include <algorithm>
#include <cassert>
#include <deque>
#include <set>
#include <vector>
#include <sstream>
#include <string>
#include <algorithm>
#include <cassert>
#include <utility>
#include <vector>

#include "cpp_common/pgr_assert.h"

Expand Down Expand Up @@ -69,14 +70,14 @@ Pg_points_graph::edges_of_points() const {


Pg_points_graph::Pg_points_graph(
std::vector<Point_on_edge_t> p_points,
const std::vector<Point_on_edge_t>& p_points,
std::vector<Edge_t> 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) {
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 003b144

Please sign in to comment.