Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove implementations of GetHashCode() from several classes #21

Merged
merged 2 commits into from
Aug 7, 2018
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
11 changes: 5 additions & 6 deletions source/System/ComponentModel/EditorBrowsableAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public enum EditorBrowsableState
/// Specifies that a property or method is viewable in an editor. This class cannot be inherited.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate)]
#pragma warning disable CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
///////////////////////////////////////////////////////////////////////////////////////////////////////
// GetHashCode() implementation is provided by general native function CLR_RT_HeapBlock::GetHashCode //
///////////////////////////////////////////////////////////////////////////////////////////////////////
public sealed class EditorBrowsableAttribute : Attribute
#pragma warning restore CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
{
private readonly EditorBrowsableState _browsableState;

Expand Down Expand Up @@ -74,11 +79,5 @@ public EditorBrowsableState State
return _browsableState;
}
}

/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A 32-bit signed integer hash code.</returns>
public override int GetHashCode() => base.GetHashCode();
}
}
16 changes: 7 additions & 9 deletions source/System/Delegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ namespace System
/// Represents a delegate, which is a data structure that refers to a static method or to a class instance and an instance method of that class.
/// </summary>
[Serializable]
#pragma warning disable CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
#pragma warning disable CS0661 // Type defines operator == or operator != but does not override Object.GetHashCode()
///////////////////////////////////////////////////////////////////////////////////////////////////////
// GetHashCode() implementation is provided by general native function CLR_RT_HeapBlock::GetHashCode //
///////////////////////////////////////////////////////////////////////////////////////////////////////
public abstract class Delegate
#pragma warning restore CS0661 // Type defines operator == or operator != but does not override Object.GetHashCode()
#pragma warning restore CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
{

/// <summary>
Expand Down Expand Up @@ -81,14 +88,5 @@ public extern Object Target
/// <returns>true if d1 is not equal to d2; otherwise, false.</returns>
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern bool operator !=(Delegate d1, Delegate d2);

/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A 32-bit signed integer hash code.</returns>
public override int GetHashCode()
{
return GetType().GetHashCode();
}
}
}
16 changes: 7 additions & 9 deletions source/System/MulticastDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ namespace System
/// Represents a multicast delegate; that is, a delegate that can have more than one element in its invocation list.
/// </summary>
[Serializable]
#pragma warning disable CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
#pragma warning disable CS0661 // Type defines operator == or operator != but does not override Object.GetHashCode()
///////////////////////////////////////////////////////////////////////////////////////////////////////
// GetHashCode() implementation is provided by general native function CLR_RT_HeapBlock::GetHashCode //
///////////////////////////////////////////////////////////////////////////////////////////////////////
public abstract class MulticastDelegate : Delegate
#pragma warning restore CS0661 // Type defines operator == or operator != but does not override Object.GetHashCode()
#pragma warning restore CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
{

/// <summary>
Expand All @@ -33,15 +40,6 @@ public abstract class MulticastDelegate : Delegate
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern bool operator !=(MulticastDelegate d1, MulticastDelegate d2);

/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A 32-bit signed integer hash code.</returns>
public override sealed int GetHashCode()
{
return base.GetHashCode();
}

/// <summary>
/// Returns the hash code for this instance.
/// </summary>
Expand Down
42 changes: 7 additions & 35 deletions source/System/String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ namespace System
/// Represents text as a sequence of UTF-16 code units.
/// </summary>
[Serializable]
#pragma warning disable CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
#pragma warning disable CS0661 // Type defines operator == or operator != but does not override Object.GetHashCode()
///////////////////////////////////////////////////////////////////////////////////////////////////////
// GetHashCode() implementation is provided by general native function CLR_RT_HeapBlock::GetHashCode //
///////////////////////////////////////////////////////////////////////////////////////////////////////
public sealed class String : IComparable
#pragma warning restore CS0661 // Type defines operator == or operator != but does not override Object.GetHashCode()
#pragma warning restore CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
{
/// <summary>
/// Represents the empty string. This field is read-only.
Expand Down Expand Up @@ -772,40 +779,5 @@ public String PadRight(int totalWidth, char paddingChar = ' ')
return this + new String(paddingChar, totalWidth - Length);
}
}

/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A 32-bit signed integer hash code.</returns>
public override int GetHashCode()
{

unsafe
{
fixed (char* src = this)
{
int hash1 = (5381<<16) + 5381;
int hash2 = hash1;

// 32 bit machines.
int* pint = (int *)src;
int len = this.Length;
while (len > 2)
{
hash1 = ((hash1 << 5) + hash1 + (hash1 >> 27)) ^ pint[0];
hash2 = ((hash2 << 5) + hash2 + (hash2 >> 27)) ^ pint[1];
pint += 2;
len -= 4;
}

if (len > 0)
{
hash1 = ((hash1 << 5) + hash1 + (hash1 >> 27)) ^ pint[0];
}

return hash1 + (hash2 * 1566083941);
}
}
}
}
}
4 changes: 3 additions & 1 deletion source/System/ValueType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ namespace System
/// </summary>
[Serializable]
#pragma warning disable CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
// It would require to implement this on a call to native which seems a waste of resources.
///////////////////////////////////////////////////////////////////////////////////////////////////////
// GetHashCode() implementation is provided by general native function CLR_RT_HeapBlock::GetHashCode //
///////////////////////////////////////////////////////////////////////////////////////////////////////
public abstract class ValueType
#pragma warning restore CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
{
Expand Down