mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:57:35 +00:00
LibGfx: Make Matrix and VectorN more constexpr-friendly
This allows the copy constructor of Matrix to be called constexpr, which should allow more values to be compile-time calculated. Likewise, VectorN.data() is now constexpr so that it can be compile-time evaluated.
This commit is contained in:
parent
0994e6964b
commit
ba79de0439
2 changed files with 15 additions and 5 deletions
|
@ -36,13 +36,23 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix(Matrix const& other)
|
constexpr Matrix(Matrix const& other)
|
||||||
{
|
{
|
||||||
__builtin_memcpy(m_elements, other.elements(), sizeof(T) * N * N);
|
*this = other;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix& operator=(Matrix const& other)
|
constexpr Matrix& operator=(Matrix const& other)
|
||||||
{
|
{
|
||||||
|
#ifndef __clang__
|
||||||
|
if (is_constant_evaluated()) {
|
||||||
|
for (size_t i = 0; i < N; i++) {
|
||||||
|
for (size_t j = 0; j < N; j++) {
|
||||||
|
m_elements[i][j] = other.elements()[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
__builtin_memcpy(m_elements, other.elements(), sizeof(T) * N * N);
|
__builtin_memcpy(m_elements, other.elements(), sizeof(T) * N * N);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,8 +251,8 @@ public:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& data() { return m_data; }
|
constexpr auto& data() { return m_data; }
|
||||||
auto const& data() const { return m_data; }
|
constexpr auto const& data() const { return m_data; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AK::Array<T, N> m_data;
|
AK::Array<T, N> m_data;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue