Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/UnityMvvmToolkit.Core/Internal/Helpers/HashCodeHelper.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using System;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityMvvmToolkit.Core.Interfaces;

namespace UnityMvvmToolkit.Core.Internal.Helpers
{
internal static class HashCodeHelper
{
private static Dictionary<(int, int), int> s_CombinedHashCodes = new Dictionary<(int, int), int>();
private static int s_StaticHashCodeId;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetMemberHashCode(Type contextType, string memberName)
{
Expand Down Expand Up @@ -88,11 +92,12 @@ public static int GetCommandWrapperId(Type contextType, Type targetType, string
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int CombineHashCode(int hash1, int hash2)
{
var hash = 17;
hash = hash * 31 + hash1;
hash = hash * 31 + hash2;

return hash;
if (!s_CombinedHashCodes.TryGetValue((hash1, hash2), out var hashCode))
{
hashCode = s_StaticHashCodeId++;
s_CombinedHashCodes.Add((hash1, hash2), hashCode);
}
return hashCode;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand All @@ -101,4 +106,4 @@ public static int CombineHashCode(int hash1, int hash2, int hash3)
return CombineHashCode(CombineHashCode(hash1, hash2), hash3);
}
}
}
}