Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,22 @@ private static bool FilterApplyMethodBase(

#endregion

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode()
Comment thread
EgorBo marked this conversation as resolved.
Resolved
{
// CLSID types share the __ComObject handle, so preserve their identity hashes.
if (IsGenericCOMObjectImpl())
return RuntimeHelpers.GetHashCode(this);

// Fibonacci hashing moves the entropy in aligned handles into the high bits.
#if TARGET_64BIT
return (int)(((ulong)(nuint)m_handle * 0x9E3779B97F4A7C15UL) >> 32);
#else
uint hash = (uint)(nuint)m_handle * 0x9E3779B9U;
return (int)(hash ^ (hash >> 16));
Comment thread
EgorBo marked this conversation as resolved.
Resolved
#endif
Comment thread
EgorBo marked this conversation as resolved.
Resolved
}

#region Private\Internal Members

internal unsafe TypeHandle GetNativeTypeHandle()
Expand Down Expand Up @@ -3318,8 +3334,7 @@ public override unsafe Guid GUID
Guid result;
#if FEATURE_COMINTEROP
Debug.Assert(OperatingSystem.IsWindows());
// The fully qualified name is needed since the RuntimeType has a TypeHandle property.
if (System.Runtime.CompilerServices.TypeHandle.AreSameType(th, System.Runtime.CompilerServices.TypeHandle.TypeHandleOf<__ComObject>()))
if (IsGenericCOMObjectImpl())
{
GetComObjectGuidWorker(this, &result);
}
Expand Down Expand Up @@ -4045,7 +4060,8 @@ internal void CallDefaultStructConstructor(ref byte data)
protected override bool IsCOMObjectImpl() => RuntimeTypeHandle.CanCastTo(this, (RuntimeType)typeof(__ComObject));

// We need to check the type handle values - not the instances - to determine if the runtime type is a generic ComObject.
internal bool IsGenericCOMObjectImpl() => TypeHandle.Value == typeof(__ComObject).TypeHandle.Value;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal bool IsGenericCOMObjectImpl() => m_handle == RuntimeTypeHandle.ToIntPtr(typeof(__ComObject).TypeHandle);
#else
protected override bool IsCOMObjectImpl() => false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,15 @@ public override int GetHashCode()
{
MethodTable* pEEType = _pUnderlyingEEType;
if (pEEType != null)
return ((nuint)pEEType).GetHashCode();
{
// Fibonacci hashing moves the entropy in aligned handles into the high bits.
#if TARGET_64BIT
return (int)(((ulong)(nuint)pEEType * 0x9E3779B97F4A7C15UL) >> 32);
#else
uint hash = (uint)(nuint)pEEType * 0x9E3779B9U;
return (int)(hash ^ (hash >> 16));
#endif
}
return RuntimeHelpers.GetHashCode(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public override bool Equals(T? x, T? y)

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode([DisallowNull] T obj) =>
obj?.GetHashCode() ?? 0;
obj is null ? 0 : obj.GetHashCode();

// Equals method for the comparer itself.
public override bool Equals([NotNullWhen(true)] object? obj) =>
Expand Down Expand Up @@ -222,7 +222,7 @@ public override bool Equals(T? x, T? y)

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode([DisallowNull] T obj) =>
obj?.GetHashCode() ?? 0;
obj is null ? 0 : obj.GetHashCode();

// Equals method for the comparer itself.
public override bool Equals([NotNullWhen(true)] object? obj) =>
Expand Down Expand Up @@ -320,7 +320,7 @@ void ISerializable.GetObjectData(SerializationInfo info, StreamingContext contex

public override bool Equals(string? x, string? y) => string.Equals(x, y);

public override int GetHashCode([DisallowNull] string obj) => obj?.GetHashCode() ?? 0;
public override int GetHashCode([DisallowNull] string obj) => obj is null ? 0 : obj.GetHashCode();

public bool Equals(ReadOnlySpan<char> span, string target)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ public override Type GetEnumUnderlyingType()
return Enum.InternalGetUnderlyingType(this);
}

public override int GetHashCode() => RuntimeHelpers.GetHashCode(this);

internal RuntimeModule GetRuntimeModule() => RuntimeTypeHandle.GetModule(this);

protected override TypeCode GetTypeCodeImpl()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,8 @@ public override int GenericParameterPosition

#endregion

public override int GetHashCode() => RuntimeHelpers.GetHashCode(this);

public static bool operator ==(RuntimeType? left, RuntimeType? right)
{
return ReferenceEquals(left, right);
Expand Down
Loading