Skip to content
Snippets Groups Projects
Commit ca5ffd24 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[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."
parent 4dc6a1e7
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
*/ */
#include <cmath> #include <cmath>
#include <limits> #include <limits>
#include <utility>
#include "PiecewiseLinearInterpolation.h" #include "PiecewiseLinearInterpolation.h"
...@@ -20,10 +21,12 @@ ...@@ -20,10 +21,12 @@
namespace MathLib namespace MathLib
{ {
PiecewiseLinearInterpolation::PiecewiseLinearInterpolation(const std::vector<double>& supporting_points, PiecewiseLinearInterpolation::PiecewiseLinearInterpolation(
const std::vector<double>& values_at_supp_pnts, std::vector<double> supporting_points,
bool supp_pnts_sorted) : std::vector<double> values_at_supp_pnts,
_supp_pnts(supporting_points), _values_at_supp_pnts(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) { if (!supp_pnts_sorted) {
BaseLib::quicksort<double, double>(_supp_pnts, static_cast<std::size_t> (0), BaseLib::quicksort<double, double>(_supp_pnts, static_cast<std::size_t> (0),
...@@ -31,12 +34,14 @@ PiecewiseLinearInterpolation::PiecewiseLinearInterpolation(const std::vector<dou ...@@ -31,12 +34,14 @@ PiecewiseLinearInterpolation::PiecewiseLinearInterpolation(const std::vector<dou
} }
} }
PiecewiseLinearInterpolation::PiecewiseLinearInterpolation(const std::vector<double>& supporting_points, PiecewiseLinearInterpolation::PiecewiseLinearInterpolation(
const std::vector<double>& values_at_supp_pnts, std::vector<double> supporting_points,
const std::vector<double>& points_to_interpolate, std::vector<double> values_at_supp_pnts,
std::vector<double>& values_at_interpol_pnts, const std::vector<double>& points_to_interpolate,
bool supp_pnts_sorted) : std::vector<double>& values_at_interpol_pnts,
_supp_pnts(supporting_points), _values_at_supp_pnts(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) { if (!supp_pnts_sorted) {
BaseLib::quicksort<double, double>(_supp_pnts, static_cast<std::size_t> (0), BaseLib::quicksort<double, double>(_supp_pnts, static_cast<std::size_t> (0),
......
...@@ -44,8 +44,8 @@ public: ...@@ -44,8 +44,8 @@ public:
* @param supp_pnts_sorted false (default), if it is sure the supporting points are sorted * @param supp_pnts_sorted false (default), if it is sure the supporting points are sorted
* one can set the switch to true * one can set the switch to true
*/ */
PiecewiseLinearInterpolation(const std::vector<double>& supporting_points, PiecewiseLinearInterpolation(std::vector<double> supporting_points,
const std::vector<double>& values_at_supp_pnts, std::vector<double> values_at_supp_pnts,
bool supp_pnts_sorted = false); bool supp_pnts_sorted = false);
/** /**
* The same requirements on the input vectors supporting_points and values_at_supp_pnts * The same requirements on the input vectors supporting_points and values_at_supp_pnts
...@@ -60,8 +60,8 @@ public: ...@@ -60,8 +60,8 @@ public:
* @param supp_pnts_sorted Is set to false per default. If it is sure that the supporting * @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. * points are sorted one can set the switch to true.
*/ */
PiecewiseLinearInterpolation(const std::vector<double>& supporting_points, PiecewiseLinearInterpolation(std::vector<double> supporting_points,
const std::vector<double>& values_at_supp_pnts, std::vector<double> values_at_supp_pnts,
const std::vector<double>& points_to_interpolate, const std::vector<double>& points_to_interpolate,
std::vector<double>& values_at_interpol_pnts, std::vector<double>& values_at_interpol_pnts,
bool supp_pnts_sorted = false); bool supp_pnts_sorted = false);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment