optimize vector component access

This commit is contained in:
Tr1NgleDev 2024-07-16 03:58:48 +08:00
parent 33b4a621a6
commit f6230f8869
3 changed files with 6 additions and 60 deletions

View file

@ -106,28 +106,14 @@ namespace glm
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & vec<2, T, Q>::operator[](typename vec<2, T, Q>::length_type i)
{
GLM_ASSERT_LENGTH(i, this->length());
switch(i)
{
default:
case 0:
return x;
case 1:
return y;
}
return (&x)[i];
}
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& vec<2, T, Q>::operator[](typename vec<2, T, Q>::length_type i) const
{
GLM_ASSERT_LENGTH(i, this->length());
switch(i)
{
default:
case 0:
return x;
case 1:
return y;
}
return (&x)[i];
}
// -- Unary arithmetic operators --

View file

@ -171,32 +171,14 @@ namespace glm
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & vec<3, T, Q>::operator[](typename vec<3, T, Q>::length_type i)
{
GLM_ASSERT_LENGTH(i, this->length());
switch(i)
{
default:
case 0:
return x;
case 1:
return y;
case 2:
return z;
}
return (&x)[i];
}
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& vec<3, T, Q>::operator[](typename vec<3, T, Q>::length_type i) const
{
GLM_ASSERT_LENGTH(i, this->length());
switch(i)
{
default:
case 0:
return x;
case 1:
return y;
case 2:
return z;
}
return (&x)[i];
}
// -- Unary arithmetic operators --

View file

@ -362,36 +362,14 @@ namespace detail
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T& vec<4, T, Q>::operator[](typename vec<4, T, Q>::length_type i)
{
GLM_ASSERT_LENGTH(i, this->length());
switch (i)
{
default:
case 0:
return x;
case 1:
return y;
case 2:
return z;
case 3:
return w;
}
return (&x)[i];
}
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& vec<4, T, Q>::operator[](typename vec<4, T, Q>::length_type i) const
{
GLM_ASSERT_LENGTH(i, this->length());
switch (i)
{
default:
case 0:
return x;
case 1:
return y;
case 2:
return z;
case 3:
return w;
}
return (&x)[i];
}
// -- Unary arithmetic operators --