Skip to content

Commit

Permalink
Math: micro-optimize vector isInf() and isNan() on Debug builds.
Browse files Browse the repository at this point in the history
The change won't make any difference in Release, but in Debug builds it
avoids calling into set() for every element. This function showed up
pretty high in profiler output for DebugTools::CompareImage, now it
doesn't anymore. In particular, for ShadersMeshVisualizerGLTest it
results in ~10% reduction in run time, which is quite significant.
  • Loading branch information
mosra committed Apr 9, 2023
1 parent 3e1ce9f commit d41ab08
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Magnum/Math/Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ template<class T> inline typename std::enable_if<IsScalar<T>::value, bool>::type
template<std::size_t size, class T> inline BitVector<size> isInf(const Vector<size, T>& value) {
BitVector<size> out;
for(std::size_t i = 0; i != size; ++i)
out.set(i, Math::isInf(value[i]));
if(Math::isInf(value[i])) out.set(i);
return out;
}

Expand All @@ -278,7 +278,7 @@ template<class T> typename std::enable_if<IsScalar<T>::value, bool>::type isNan(
template<std::size_t size, class T> inline BitVector<size> isNan(const Vector<size, T>& value) {
BitVector<size> out;
for(std::size_t i = 0; i != size; ++i)
out.set(i, Math::isNan(value[i]));
if(Math::isNan(value[i])) out.set(i);
return out;
}

Expand Down

0 comments on commit d41ab08

Please sign in to comment.