From 954246d10ec3c9b6c84569f217d6728e53529341 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 30 May 2019 02:06:55 -0400 Subject: [PATCH] VideoCommon/ShaderGenCommon: Remove use of a union within ShaderUid This is only ever used to retrieve a raw view of the given UID data structure, however it's already valid C++ to retrieve a char/unsigned char view of an object for bytewise inspection. u8 maps to unsigned char on all platforms we support, so we can just do this directly with a reinterpret cast, simplifying the overall interface. --- Source/Core/VideoCommon/ShaderGenCommon.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Source/Core/VideoCommon/ShaderGenCommon.h b/Source/Core/VideoCommon/ShaderGenCommon.h index 3dd125b2ca..137b0487dd 100644 --- a/Source/Core/VideoCommon/ShaderGenCommon.h +++ b/Source/Core/VideoCommon/ShaderGenCommon.h @@ -69,18 +69,18 @@ public: bool operator==(const ShaderUid& obj) const { - return memcmp(this->values, obj.values, data.NumValues() * sizeof(*values)) == 0; + return memcmp(&data, &obj.data, data.NumValues() * sizeof(data)) == 0; } bool operator!=(const ShaderUid& obj) const { - return memcmp(this->values, obj.values, data.NumValues() * sizeof(*values)) != 0; + return memcmp(&data, &obj.data, data.NumValues() * sizeof(data)) != 0; } // determines the storage order inside STL containers bool operator<(const ShaderUid& obj) const { - return memcmp(this->values, obj.values, data.NumValues() * sizeof(*values)) < 0; + return memcmp(&data, &obj.data, data.NumValues() * sizeof(data)) < 0; } // Returns a pointer to an internally stored object of the uid_data type. @@ -90,17 +90,13 @@ public: const uid_data* GetUidData() const { return &data; } // Returns the raw bytes that make up the shader UID. - const u8* GetUidDataRaw() const { return &values[0]; } + const u8* GetUidDataRaw() const { return reinterpret_cast(&data); } // Returns the size of the underlying UID data structure in bytes. - size_t GetUidDataSize() const { return sizeof(values); } + size_t GetUidDataSize() const { return sizeof(data); } private: - union - { - uid_data data{}; - u8 values[sizeof(uid_data)]; - }; + uid_data data{}; }; class ShaderCode : public ShaderGeneratorInterface