Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[util] Pass range into math::polyval() instead of std::vector
This is done to avoid creating a separate container in each
iteration.
  • Loading branch information
adl1995 committed Jun 28, 2018
1 parent 1fe3b3b commit 6219503
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
11 changes: 6 additions & 5 deletions include/boost/geometry/util/math.hpp
Expand Up @@ -855,18 +855,19 @@ inline NT horner_evaluate(NT x,
/*
\brief Evaluate the polynomial.
*/
template<typename CT>
inline CT polyval(std::vector<CT> coeff,
template<typename IteratorType, typename CT>
inline CT polyval(IteratorType first,
IteratorType last,
const CT eps)
{
int N = boost::size(coeff) - 1;
int N = std::distance(first, last) - 1;
int index = 0;

CT y = N < 0 ? 0 : coeff[index++];
CT y = N < 0 ? 0 : *(first + (index++));

while (--N >= 0)
{
y = y * eps + coeff[index++];
y = y * eps + *(first + (index++));
}

return y;
Expand Down
3 changes: 1 addition & 2 deletions include/boost/geometry/util/series_expansion.hpp
Expand Up @@ -642,8 +642,7 @@ namespace boost { namespace geometry { namespace series_expansion {
int m = Coeffs1::static_size - l - 1;
mult *= eps;

std::vector<CT> coeffs2_slice(coeffs2.begin(), coeffs2.begin() + offset);
coeffs1[l] = mult * math::polyval(coeffs2_slice, eps);
coeffs1[l] = mult * math::polyval(coeffs2.begin(), coeffs2.begin() + offset, eps);

offset += m + 1;
}
Expand Down

0 comments on commit 6219503

Please sign in to comment.