From d41ab088803a5d5eefdecef6b8a376db51a8fcd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 9 Apr 2023 11:04:08 +0200 Subject: [PATCH] Math: micro-optimize vector isInf() and isNan() on Debug builds. 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. --- src/Magnum/Math/Functions.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Magnum/Math/Functions.h b/src/Magnum/Math/Functions.h index 4afe441eb..34328e704 100644 --- a/src/Magnum/Math/Functions.h +++ b/src/Magnum/Math/Functions.h @@ -256,7 +256,7 @@ template inline typename std::enable_if::value, bool>::type template inline BitVector isInf(const Vector& value) { BitVector 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; } @@ -278,7 +278,7 @@ template typename std::enable_if::value, bool>::type isNan( template inline BitVector isNan(const Vector& value) { BitVector 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; }