Commit 1d6f2be4 authored by Damien L-G's avatar Damien L-G

On 2nd thought make Map::get_spline() return a const reference to Spline

parent 94ba06ab
......@@ -60,7 +60,7 @@ BENCHMARK(BM_EvalRawGSL);
static void BM_EvalMap(benchmark::State &state) {
Map<Spline2D<Bicubic>>::get_spline(k);
for (auto _ : state) {
Map<Spline2D<Bicubic>>::get_spline(k)->eval(_x.back(), _y.front());
Map<Spline2D<Bicubic>>::get_spline(k).eval(_x.back(), _y.front());
}
}
BENCHMARK(BM_EvalMap);
......
......@@ -77,7 +77,7 @@ void check_valid_number_of_options(std::vector<std::string> const &options,
}
template <typename Spline>
Spline const *Map<Spline>::get_spline(std::string const &which) {
Spline const &Map<Spline>::get_spline(std::string const &which) {
auto it = _splines.find(which);
if (it == _splines.end()) {
auto const options = parse_options(which);
......@@ -99,7 +99,7 @@ Spline const *Map<Spline>::get_spline(std::string const &which) {
std::tie(it, std::ignore) = _splines.emplace(
which, Spline(std::move(x), std::move(y), std::move(z)));
}
return &it->second;
return it->second;
}
template <typename Spline> std::map<std::string, Spline> Map<Spline>::_splines;
......
......@@ -10,7 +10,7 @@ namespace noname {
template <typename Spline> class Map {
public:
static Spline const *get_spline(std::string const &which);
static Spline const &get_spline(std::string const &which);
static int size() { return _splines.size(); }
static void clear() { _splines.clear(); }
......
......@@ -6,61 +6,61 @@
using namespace noname;
double bilinear_eval(char const *o, double x, double y) {
auto spline = Map<Spline2D<Bilinear>>::get_spline(o);
return spline->eval(x, y);
auto const &spline = Map<Spline2D<Bilinear>>::get_spline(o);
return spline.eval(x, y);
}
double bilinear_eval_deriv_x(char const *o, double x, double y) {
auto spline = Map<Spline2D<Bilinear>>::get_spline(o);
return spline->eval_deriv_x(x, y);
auto const &spline = Map<Spline2D<Bilinear>>::get_spline(o);
return spline.eval_deriv_x(x, y);
}
double bilinear_eval_deriv_y(char const *o, double x, double y) {
auto spline = Map<Spline2D<Bilinear>>::get_spline(o);
return spline->eval_deriv_y(x, y);
auto const &spline = Map<Spline2D<Bilinear>>::get_spline(o);
return spline.eval_deriv_y(x, y);
}
double bilinear_eval_deriv_xx(char const *o, double x, double y) {
auto spline = Map<Spline2D<Bilinear>>::get_spline(o);
return spline->eval_deriv_xx(x, y);
auto const &spline = Map<Spline2D<Bilinear>>::get_spline(o);
return spline.eval_deriv_xx(x, y);
}
double bilinear_eval_deriv_yy(char const *o, double x, double y) {
auto spline = Map<Spline2D<Bilinear>>::get_spline(o);
return spline->eval_deriv_yy(x, y);
auto const &spline = Map<Spline2D<Bilinear>>::get_spline(o);
return spline.eval_deriv_yy(x, y);
}
double bilinear_eval_deriv_xy(char const *o, double x, double y) {
auto spline = Map<Spline2D<Bilinear>>::get_spline(o);
return spline->eval_deriv_xy(x, y);
auto const &spline = Map<Spline2D<Bilinear>>::get_spline(o);
return spline.eval_deriv_xy(x, y);
}
double bilinear_eval_extrap(char const *o, double x, double y) {
auto spline = Map<Spline2D<Bilinear>>::get_spline(o);
return spline->eval_extrap(x, y);
auto const &spline = Map<Spline2D<Bilinear>>::get_spline(o);
return spline.eval_extrap(x, y);
}
double bicubic_eval(char const *o, double x, double y) {
auto spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline->eval(x, y);
auto const &spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline.eval(x, y);
}
double bicubic_eval_deriv_x(char const *o, double x, double y) {
auto spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline->eval_deriv_x(x, y);
auto const &spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline.eval_deriv_x(x, y);
}
double bicubic_eval_deriv_y(char const *o, double x, double y) {
auto spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline->eval_deriv_y(x, y);
auto const &spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline.eval_deriv_y(x, y);
}
double bicubic_eval_deriv_xx(char const *o, double x, double y) {
auto spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline->eval_deriv_xx(x, y);
auto const &spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline.eval_deriv_xx(x, y);
}
double bicubic_eval_deriv_yy(char const *o, double x, double y) {
auto spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline->eval_deriv_yy(x, y);
auto const &spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline.eval_deriv_yy(x, y);
}
double bicubic_eval_deriv_xy(char const *o, double x, double y) {
auto spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline->eval_deriv_xy(x, y);
auto const &spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline.eval_deriv_xy(x, y);
}
double bicubic_eval_extrap(char const *o, double x, double y) {
auto spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline->eval_extrap(x, y);
auto const &spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline.eval_extrap(x, y);
}
// NOTE can get rid of these with C++17
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment