From b6b113cc2b41797367ace0f91c29c0118b6c301a Mon Sep 17 00:00:00 2001 From: Hein-Pieter van Braam Date: Tue, 19 Feb 2019 21:24:59 +0000 Subject: [PATCH] Align the Variant data member This should avoid potential alignment issues when _mem holds real values and speed up some floating point operations in some cases. --- core/variant.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/variant.h b/core/variant.h index a819ba1f8cf..9215d15bf05 100644 --- a/core/variant.h +++ b/core/variant.h @@ -69,6 +69,13 @@ typedef PoolVector PoolVector2Array; typedef PoolVector PoolVector3Array; typedef PoolVector PoolColorArray; +// Temporary workaround until c++11 alignas() +#ifdef __GNUC__ +#define GCC_ALIGNED_8 __attribute__((aligned(8))) +#else +#define GCC_ALIGNED_8 +#endif + class Variant { public: // If this changes the table in variant_op must be updated @@ -132,7 +139,6 @@ private: _FORCE_INLINE_ const ObjData &_get_obj() const; union { - bool _bool; int64_t _int; double _real; @@ -142,7 +148,7 @@ private: Transform *_transform; void *_ptr; //generic pointer uint8_t _mem[sizeof(ObjData) > (sizeof(real_t) * 4) ? sizeof(ObjData) : (sizeof(real_t) * 4)]; - } _data; + } _data GCC_ALIGNED_8; void reference(const Variant &p_variant); void clear();