From ca5ffd2490e9cfe5bf14b2b9d8a8505cf8422703 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Tue, 19 Apr 2016 14:33:20 +0200 Subject: [PATCH] [MaL] Pass args by value to PiecewiseLinInterpol. Reasoning: The vector's move operation is cheap and it covers the two cases of passed l-values and r-values w/o code duplication and templates. According to "Effective modern c++" Item 41: "Consider pass by value for copyable parameters that are cheap to move and always copied." --- .../PiecewiseLinearInterpolation.cpp | 25 +++++++++++-------- .../PiecewiseLinearInterpolation.h | 8 +++--- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.cpp b/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.cpp index 74c8b5ac8bd..c8b4084ffba 100644 --- a/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.cpp +++ b/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.cpp @@ -13,6 +13,7 @@ */ #include <cmath> #include <limits> +#include <utility> #include "PiecewiseLinearInterpolation.h" @@ -20,10 +21,12 @@ namespace MathLib { -PiecewiseLinearInterpolation::PiecewiseLinearInterpolation(const std::vector<double>& supporting_points, - const std::vector<double>& values_at_supp_pnts, - bool supp_pnts_sorted) : - _supp_pnts(supporting_points), _values_at_supp_pnts(values_at_supp_pnts) +PiecewiseLinearInterpolation::PiecewiseLinearInterpolation( + std::vector<double> supporting_points, + std::vector<double> values_at_supp_pnts, + bool supp_pnts_sorted) + : _supp_pnts(std::move(supporting_points)), + _values_at_supp_pnts(std::move(values_at_supp_pnts)) { if (!supp_pnts_sorted) { BaseLib::quicksort<double, double>(_supp_pnts, static_cast<std::size_t> (0), @@ -31,12 +34,14 @@ PiecewiseLinearInterpolation::PiecewiseLinearInterpolation(const std::vector<dou } } -PiecewiseLinearInterpolation::PiecewiseLinearInterpolation(const std::vector<double>& supporting_points, - const std::vector<double>& values_at_supp_pnts, - const std::vector<double>& points_to_interpolate, - std::vector<double>& values_at_interpol_pnts, - bool supp_pnts_sorted) : - _supp_pnts(supporting_points), _values_at_supp_pnts(values_at_supp_pnts) +PiecewiseLinearInterpolation::PiecewiseLinearInterpolation( + std::vector<double> supporting_points, + std::vector<double> values_at_supp_pnts, + const std::vector<double>& points_to_interpolate, + std::vector<double>& values_at_interpol_pnts, + bool supp_pnts_sorted) + : _supp_pnts(std::move(supporting_points)), + _values_at_supp_pnts(std::move(values_at_supp_pnts)) { if (!supp_pnts_sorted) { BaseLib::quicksort<double, double>(_supp_pnts, static_cast<std::size_t> (0), diff --git a/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h b/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h index 6941d54460b..b3c16001303 100644 --- a/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h +++ b/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h @@ -44,8 +44,8 @@ public: * @param supp_pnts_sorted false (default), if it is sure the supporting points are sorted * one can set the switch to true */ - PiecewiseLinearInterpolation(const std::vector<double>& supporting_points, - const std::vector<double>& values_at_supp_pnts, + PiecewiseLinearInterpolation(std::vector<double> supporting_points, + std::vector<double> values_at_supp_pnts, bool supp_pnts_sorted = false); /** * The same requirements on the input vectors supporting_points and values_at_supp_pnts @@ -60,8 +60,8 @@ public: * @param supp_pnts_sorted Is set to false per default. If it is sure that the supporting * points are sorted one can set the switch to true. */ - PiecewiseLinearInterpolation(const std::vector<double>& supporting_points, - const std::vector<double>& values_at_supp_pnts, + PiecewiseLinearInterpolation(std::vector<double> supporting_points, + std::vector<double> values_at_supp_pnts, const std::vector<double>& points_to_interpolate, std::vector<double>& values_at_interpol_pnts, bool supp_pnts_sorted = false); -- GitLab