Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove TryGetHashCode from Mono
It does not guarantee that hash codes are non-zero.
  • Loading branch information
AustinWise committed Dec 30, 2022
commit d9a6dc22b4c3afdb35f450c258ad7c3ffc3011fb
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,10 @@ internal int FindEntry(TKey key, out object? value)
{
Debug.Assert(key != null); // Key already validated as non-null.

int hashCode = RuntimeHelpers.TryGetHashCode(key);
int hashCode;

#if CORECLR || NATIVEAOT
hashCode = RuntimeHelpers.TryGetHashCode(key);

if (hashCode == 0)
{
Expand All @@ -547,6 +550,9 @@ internal int FindEntry(TKey key, out object? value)
value = null;
return -1;
}
#else
hashCode = RuntimeHelpers.GetHashCode(key);
#endif

hashCode &= int.MaxValue;
int bucket = hashCode & (_buckets.Length - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ public static int GetHashCode(object? o)
return InternalGetHashCode(o);
}

internal static int TryGetHashCode(object o)
{
// On Mono the fast path is not yet implemented, so we just defer to GetHashCode.
return InternalGetHashCode(o);
}

public static new bool Equals(object? o1, object? o2)
{
if (o1 == o2)
Expand Down