From 5bfaa3a966f01301ca8e856963628c6fdf68cb7d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 31 Jan 2024 12:37:41 -0500 Subject: [PATCH 1/4] NativeVertexFormat: Collapse std namespace and mark hash noexcept We can just tag the std:: onto the end of the specialization to make it less noisy. Also mark it as noexcept, since hashes shouldn't throw exceptions. --- Source/Core/VideoCommon/NativeVertexFormat.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Core/VideoCommon/NativeVertexFormat.h b/Source/Core/VideoCommon/NativeVertexFormat.h index 597f492e9e..0f6be25541 100644 --- a/Source/Core/VideoCommon/NativeVertexFormat.h +++ b/Source/Core/VideoCommon/NativeVertexFormat.h @@ -79,14 +79,12 @@ struct PortableVertexDeclaration static_assert(std::is_trivially_copyable_v, "Make sure we can memset-initialize"); -namespace std -{ template <> -struct hash +struct std::hash { // Implementation from Wikipedia. template - u32 Fletcher32(const T& data) const + static u32 Fletcher32(const T& data) { static_assert(sizeof(T) % sizeof(u16) == 0); @@ -114,9 +112,11 @@ struct hash sum2 = (sum2 & 0xffff) + (sum2 >> 16); return (sum2 << 16 | sum1); } - size_t operator()(const PortableVertexDeclaration& decl) const { return Fletcher32(decl); } + size_t operator()(const PortableVertexDeclaration& decl) const noexcept + { + return Fletcher32(decl); + } }; -} // namespace std // The implementation of this class is specific for GL/DX, so NativeVertexFormat.cpp // is in the respective backend, not here in VideoCommon. From b63dcd504daed02412609057703fc2f418eec095 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 31 Jan 2024 12:40:08 -0500 Subject: [PATCH 2/4] RenderState: Collapse std namespace for hash We can specify the namespace on the hash to make the specialization a little less noisy. --- Source/Core/VideoCommon/RenderState.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Source/Core/VideoCommon/RenderState.h b/Source/Core/VideoCommon/RenderState.h index 8e0902b88e..4a682b1a0f 100644 --- a/Source/Core/VideoCommon/RenderState.h +++ b/Source/Core/VideoCommon/RenderState.h @@ -220,17 +220,14 @@ struct SamplerState TM1 tm1; }; -namespace std -{ template <> -struct hash +struct std::hash { - std::size_t operator()(SamplerState const& state) const noexcept + std::size_t operator()(const SamplerState& state) const noexcept { return std::hash{}(state.Hex()); } }; -} // namespace std namespace RenderState { From 8e4b2565cd79c896aa20a670562fd6dc9cd2b161 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 31 Jan 2024 12:41:30 -0500 Subject: [PATCH 3/4] TextureConfig: Collapse std namespace for hash Lets us collapse the namespacing and make the specialization a little less noisy. --- Source/Core/VideoCommon/TextureConfig.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Source/Core/VideoCommon/TextureConfig.h b/Source/Core/VideoCommon/TextureConfig.h index 462b3dddff..4e3976f938 100644 --- a/Source/Core/VideoCommon/TextureConfig.h +++ b/Source/Core/VideoCommon/TextureConfig.h @@ -79,10 +79,8 @@ struct TextureConfig AbstractTextureType type = AbstractTextureType::Texture_2DArray; }; -namespace std -{ template <> -struct hash +struct std::hash { using argument_type = TextureConfig; using result_type = size_t; @@ -95,4 +93,3 @@ struct hash return std::hash{}(id); } }; -} // namespace std From 0dfefacdf45e4662043a3ea39d5c0e612329393b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 31 Jan 2024 12:42:57 -0500 Subject: [PATCH 4/4] VertexLoaderBase: Collapse std namespace for hash and mark noexcept Makes the hash specialization a little less noisy. Also we mark it noexcept, since hashes shouldn't be throwing exceptions (and this can be optimized on). --- Source/Core/VideoCommon/VertexLoaderBase.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Source/Core/VideoCommon/VertexLoaderBase.h b/Source/Core/VideoCommon/VertexLoaderBase.h index 26d6f3ff2e..451f035793 100644 --- a/Source/Core/VideoCommon/VertexLoaderBase.h +++ b/Source/Core/VideoCommon/VertexLoaderBase.h @@ -46,14 +46,11 @@ private: } }; -namespace std -{ template <> -struct hash +struct std::hash { - size_t operator()(const VertexLoaderUID& uid) const { return uid.GetHash(); } + size_t operator()(const VertexLoaderUID& uid) const noexcept { return uid.GetHash(); } }; -} // namespace std class VertexLoaderBase {