From 4158300ea488547a97b2cff6b4d4adc00f9210b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Tue, 7 Aug 2018 10:08:20 +0100 Subject: [PATCH] Remove implementations of GetHashCode() from several classes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Simões --- .../EditorBrowsableAttribute.cs | 11 +++-- source/System/DateTime.cs | 4 +- source/System/Delegate.cs | 16 ++++--- source/System/MulticastDelegate.cs | 16 ++++--- source/System/String.cs | 42 ++++--------------- source/System/ValueType.cs | 4 +- 6 files changed, 31 insertions(+), 62 deletions(-) diff --git a/source/System/ComponentModel/EditorBrowsableAttribute.cs b/source/System/ComponentModel/EditorBrowsableAttribute.cs index c0343779..38248677 100644 --- a/source/System/ComponentModel/EditorBrowsableAttribute.cs +++ b/source/System/ComponentModel/EditorBrowsableAttribute.cs @@ -30,7 +30,12 @@ public enum EditorBrowsableState /// Specifies that a property or method is viewable in an editor. This class cannot be inherited. /// [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; @@ -74,11 +79,5 @@ public EditorBrowsableState State return _browsableState; } } - - /// - /// Returns the hash code for this instance. - /// - /// A 32-bit signed integer hash code. - public override int GetHashCode() => base.GetHashCode(); } } diff --git a/source/System/DateTime.cs b/source/System/DateTime.cs index e8dd3b5d..7c521c25 100644 --- a/source/System/DateTime.cs +++ b/source/System/DateTime.cs @@ -13,7 +13,7 @@ namespace System /// /// Specifies whether a DateTime object represents a local time, a Coordinated Universal Time (UTC), or is not specified as either local time or UTC. /// - /// nanoFramework doesn't suport local time, only UTC, so it's not possible to specify DateTimeKind.Local. + /// nanoFramework doesn't support local time, only UTC, so it's not possible to specify DateTimeKind.Local. [Serializable] public enum DateTimeKind { @@ -24,7 +24,7 @@ public enum DateTimeKind /// /// The time represented is local time. /// - [Obsolete("nanoFrameowrk doesn't support local time, so DateTimeKind.Local can't be used for consistency", true)] + [Obsolete("nanoFramework doesn't support local time, so DateTimeKind.Local can't be used for consistency", true)] Local = 2, } diff --git a/source/System/Delegate.cs b/source/System/Delegate.cs index 6225bcfb..112f668b 100644 --- a/source/System/Delegate.cs +++ b/source/System/Delegate.cs @@ -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. /// [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() { /// @@ -81,14 +88,5 @@ public extern Object Target /// true if d1 is not equal to d2; otherwise, false. [MethodImpl(MethodImplOptions.InternalCall)] public static extern bool operator !=(Delegate d1, Delegate d2); - - /// - /// Returns the hash code for this instance. - /// - /// A 32-bit signed integer hash code. - public override int GetHashCode() - { - return GetType().GetHashCode(); - } } } diff --git a/source/System/MulticastDelegate.cs b/source/System/MulticastDelegate.cs index c8257ff7..3cf487f7 100644 --- a/source/System/MulticastDelegate.cs +++ b/source/System/MulticastDelegate.cs @@ -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. /// [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() { /// @@ -33,15 +40,6 @@ public abstract class MulticastDelegate : Delegate [MethodImpl(MethodImplOptions.InternalCall)] public static extern bool operator !=(MulticastDelegate d1, MulticastDelegate d2); - /// - /// Returns the hash code for this instance. - /// - /// A 32-bit signed integer hash code. - public override sealed int GetHashCode() - { - return base.GetHashCode(); - } - /// /// Returns the hash code for this instance. /// diff --git a/source/System/String.cs b/source/System/String.cs index 218d253d..92b4d212 100644 --- a/source/System/String.cs +++ b/source/System/String.cs @@ -11,7 +11,14 @@ namespace System /// Represents text as a sequence of UTF-16 code units. /// [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() { /// /// Represents the empty string. This field is read-only. @@ -772,40 +779,5 @@ public String PadRight(int totalWidth, char paddingChar = ' ') return this + new String(paddingChar, totalWidth - Length); } } - - /// - /// Returns the hash code for this instance. - /// - /// A 32-bit signed integer hash code. - 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); - } - } - } } } diff --git a/source/System/ValueType.cs b/source/System/ValueType.cs index d7d62ceb..f78995c3 100644 --- a/source/System/ValueType.cs +++ b/source/System/ValueType.cs @@ -13,7 +13,9 @@ namespace System /// [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() {