Browse Source

Try using sizeof String as variant buffer size

Michael Ragazzon 6 years ago
parent
commit
fa0d4fd8b0
2 changed files with 5 additions and 7 deletions
  1. 3 7
      Include/Rocket/Core/Variant.h
  2. 2 0
      Source/Core/Variant.cpp

+ 3 - 7
Include/Rocket/Core/Variant.h

@@ -31,7 +31,6 @@
 #include "Header.h"
 #include "Types.h"
 #include "TypeConverter.h"
-#include <list>
 
 namespace Rocket {
 namespace Core {
@@ -137,13 +136,10 @@ private:
 	void Set(const Colourb& value);
 	void Set(ScriptInterface* value);
 	
-#ifdef ROCKET_ARCH_64
-		static const int LOCAL_DATA_SIZE = 40; // Required for Strings
-#else
-		static const int LOCAL_DATA_SIZE = 24;
-#endif
+	static constexpr size_t LOCAL_DATA_SIZE = sizeof(String);
+
 	Type type;
-	char data[LOCAL_DATA_SIZE];
+	alignas(std::max_align_t) char data[LOCAL_DATA_SIZE];
 };
 
 }

+ 2 - 0
Source/Core/Variant.cpp

@@ -36,7 +36,9 @@ Variant::Variant() : type(NONE)
 	// Make sure our object size assumptions fit inside the static buffer
 	static_assert(sizeof(Colourb) <= LOCAL_DATA_SIZE, "Local data too small for Colourb");
 	static_assert(sizeof(Colourf) <= LOCAL_DATA_SIZE, "Local data too small for Colourf");
+	static_assert(sizeof(Vector4f) <= LOCAL_DATA_SIZE, "Local data too small for Vector4f");
 	static_assert(sizeof(String) <= LOCAL_DATA_SIZE, "Local data too small for String");
+	static_assert(sizeof(TransformRef) <= LOCAL_DATA_SIZE, "Local data too small for TransformRef");
 	static_assert(sizeof(TransitionList) <= LOCAL_DATA_SIZE, "Local data too small for TransitionList");
 	static_assert(sizeof(AnimationList) <= LOCAL_DATA_SIZE, "Local data too small for AnimationList");
 }