From: Stephen Toub Date: Sat, 6 Feb 2021 12:27:37 +0000 (-0500) Subject: Remove use of string.GetHashCode(StringComparison) (#47883) X-Git-Tag: submit/tizen/20210909.063632~3411 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ce0f0b8bc3b39b8aa4b4aa6639fe505679f37c05;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Remove use of string.GetHashCode(StringComparison) (#47883) All of our call sites to it pass in a const StringComparison; GetHashCode will then turn around and decide which property on StringComparer to use, and then call GetHashCode on the relevant instance... we may as well just pick the instance directly, which not only saves the lookup and enables devirtualization, it also enables better trimming, as string.GetHashCode(StringComparison) ends up rooting all of the StringComparer properties in case you pass in the appropriate StringComparison. --- diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddress.cs b/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddress.cs index 9b4a06d..dd19ec1 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddress.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddress.cs @@ -272,7 +272,7 @@ namespace System.Net.Mail public override int GetHashCode() { - return ToString().GetHashCode(StringComparison.InvariantCultureIgnoreCase); + return StringComparer.InvariantCultureIgnoreCase.GetHashCode(ToString()); } private static readonly EncodedStreamFactory s_encoderFactory = new EncodedStreamFactory(); diff --git a/src/libraries/System.Private.Uri/src/System/Uri.cs b/src/libraries/System.Private.Uri/src/System/Uri.cs index dbb89a3..db7d057 100644 --- a/src/libraries/System.Private.Uri/src/System/Uri.cs +++ b/src/libraries/System.Private.Uri/src/System/Uri.cs @@ -1542,7 +1542,7 @@ namespace System if (IsUncOrDosPath) { - return remoteUrl.GetHashCode(StringComparison.OrdinalIgnoreCase); + return StringComparer.OrdinalIgnoreCase.GetHashCode(remoteUrl); } else { diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/OSPlatform.cs b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/OSPlatform.cs index ff36163..3416867 100644 --- a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/OSPlatform.cs +++ b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/OSPlatform.cs @@ -51,7 +51,7 @@ namespace System.Runtime.InteropServices public override int GetHashCode() { - return Name == null ? 0 : Name.GetHashCode(StringComparison.OrdinalIgnoreCase); + return Name == null ? 0 : StringComparer.OrdinalIgnoreCase.GetHashCode(Name); } public override string ToString()