godot
godot copied to clipboard
Core: Utilize initalizer lists in Math constructors
The Math equivalent of #90866, whereby the bulk of math constructors set their properties via initalizer lists. Differs from Variant in two main ways:
- Not all constructors got this treatment, as some had more advanced logic that was outside the scope of this conversion.
- Due to using exclusively primitive types, the changed constructors are all able to safely use
constexpr
. (Possible groundwork for constexpr math types? 🤔)
Wait, does making the constructors constexpr
qualify the structs for unused checks? That's... Interesting
Just to confirm, it looks like compiler is pretty good at optimizing out unneeded constructors even without initializer list, even at minimal optimization -O1
. This is trivial case though, there might be some cases where there is benefit.
https://godbolt.org/z/cYWed7fWK
This does suggest that in most cases these changes are a style preference issue, rather than functional change. However the constexpr
could be useful.
Making these constexpr revealed a strange conflict with unions: clang-tidy wants structs inside unions to have default member initalization, but a union only allows a single field initalizer and that logic includes the internals of a struct. So as of now, the default values must be part of their respective coord
array, instead of being assigned to the named variables; though, the named variables end up being what's assigned in the member initializers. Trying to alter the unions themselves is probably outside the scope of this PR, but I'll test a bit and see how invasive it would end up being; most likely outcome: it'll be part of an immediate followup PR.
Superseded by #91992.