From 3e93da7f44506f52650625dd02edc6819dadc3fe Mon Sep 17 00:00:00 2001 From: Redstone1024 <2824517378@qq.com> Date: Tue, 8 Oct 2024 21:00:50 +0800 Subject: [PATCH] perf(templates): fix unclear overloading of HashCombine --- .../Source/Public/Templates/TypeHash.h | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/Redcraft.Utility/Source/Public/Templates/TypeHash.h b/Redcraft.Utility/Source/Public/Templates/TypeHash.h index 6b2a08f..f6ef5d9 100644 --- a/Redcraft.Utility/Source/Public/Templates/TypeHash.h +++ b/Redcraft.Utility/Source/Public/Templates/TypeHash.h @@ -22,10 +22,10 @@ FORCEINLINE constexpr size_t HashCombine(size_t A) return A; } -/** Combines two hash values to get a third. this function is not commutative. */ -FORCEINLINE constexpr size_t HashCombine(size_t A, size_t C) +/** Combines more hash values to get a new value. this function is not commutative. */ +template requires (true && ... && CConvertibleTo) +FORCEINLINE constexpr size_t HashCombine(size_t A, size_t C, Ts... InOther) { - size_t B = static_cast(0x9E3779B97F4A7C16); A += B; @@ -40,15 +40,7 @@ FORCEINLINE constexpr size_t HashCombine(size_t A, size_t C) B -= C; B -= A; B ^= (A << 10); C -= A; C -= B; C ^= (B >> 15); - return C; -} - -/** Combines more hash values to get a new value. this function is not commutative. */ -template requires (true && ... && CConvertibleTo) -FORCEINLINE constexpr size_t HashCombine(size_t A, size_t C, Ts... InOther) -{ - size_t B = HashCombine(A, C); - return HashCombine(B, InOther...); + return HashCombine(C, InOther...); } /** Overloads the GetTypeHash algorithm for CIntegral. */