Browse Source

Math: directly access Vector components in gather() / scatter().

Speeding up debug builds a bit.
pull/326/merge
Vladimír Vondruš 7 years ago
parent
commit
f2f1cac598
  1. 4
      src/Magnum/Math/Swizzle.h
  2. 6
      src/Magnum/Math/Vector.h

4
src/Magnum/Math/Swizzle.h

@ -38,7 +38,7 @@ namespace Implementation {
static_assert(size > position, "swizzle parameter out of range of gather vector"); static_assert(size > position, "swizzle parameter out of range of gather vector");
template<class T> constexpr static T value(const Math::Vector<size, T>& vector) { template<class T> constexpr static T value(const Math::Vector<size, T>& vector) {
return vector[position]; return vector._data[position];
} }
}; };
@ -70,7 +70,7 @@ namespace Implementation {
"swizzle parameter out of range of scatter vector"); "swizzle parameter out of range of scatter vector");
template<class T> constexpr static T value(const Math::Vector<size, T>& vector, const T&) { template<class T> constexpr static T value(const Math::Vector<size, T>& vector, const T&) {
return vector[i]; return vector._data[i];
} }
}; };
template<std::size_t size, std::size_t position> struct Value { template<std::size_t size, std::size_t position> struct Value {

6
src/Magnum/Math/Vector.h

@ -81,6 +81,9 @@ namespace Implementation {
/* Used to make friends to speed up debug builds */ /* Used to make friends to speed up debug builds */
template<std::size_t, class> struct MatrixDeterminant; template<std::size_t, class> struct MatrixDeterminant;
/* To make gather() / scatter() faster */
template<std::size_t, std::size_t> struct ComponentAtPosition;
template<std::size_t, char, std::size_t> struct ComponentOr;
} }
/** @relatesalso Vector /** @relatesalso Vector
@ -652,6 +655,9 @@ template<std::size_t size, class T> class Vector {
template<std::size_t, std::size_t, class> friend class RectangularMatrix; template<std::size_t, std::size_t, class> friend class RectangularMatrix;
template<std::size_t, class> friend class Matrix; template<std::size_t, class> friend class Matrix;
template<std::size_t, class> friend struct Implementation::MatrixDeterminant; template<std::size_t, class> friend struct Implementation::MatrixDeterminant;
/* To make gather() / scatter() faster */
template<std::size_t, std::size_t> friend struct Implementation::ComponentAtPosition;
template<std::size_t, char, std::size_t> friend struct Implementation::ComponentOr;
/* So the out-of-class comparators can access data directly to avoid /* So the out-of-class comparators can access data directly to avoid
function call overhead */ function call overhead */

Loading…
Cancel
Save