summaryrefslogtreecommitdiff
path: root/src/System.Private.CoreLib/shared/System/String.Comparison.cs
diff options
context:
space:
mode:
authorLevi Broderick <GrabYourPitchforks@users.noreply.github.com>2018-10-11 16:25:20 -0700
committerGitHub <noreply@github.com>2018-10-11 16:25:20 -0700
commite2bcca7d9d0e36510eaba9b1028e16a5de39cee9 (patch)
tree137065ea7bf2f8af53e71e3249557812824a041c /src/System.Private.CoreLib/shared/System/String.Comparison.cs
parent907c013a7f5bf6ef4e37519ca27b7ea6fb998153 (diff)
downloadcoreclr-e2bcca7d9d0e36510eaba9b1028e16a5de39cee9.tar.gz
coreclr-e2bcca7d9d0e36510eaba9b1028e16a5de39cee9.tar.bz2
coreclr-e2bcca7d9d0e36510eaba9b1028e16a5de39cee9.zip
Improve performance of OrdinalIgnoreCase hash code calculation (#20309)
Diffstat (limited to 'src/System.Private.CoreLib/shared/System/String.Comparison.cs')
-rw-r--r--src/System.Private.CoreLib/shared/System/String.Comparison.cs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/System.Private.CoreLib/shared/System/String.Comparison.cs b/src/System.Private.CoreLib/shared/System/String.Comparison.cs
index 8ac31796bb..f20f6c3c94 100644
--- a/src/System.Private.CoreLib/shared/System/String.Comparison.cs
+++ b/src/System.Private.CoreLib/shared/System/String.Comparison.cs
@@ -744,15 +744,24 @@ namespace System
// Gets a hash code for this string. If strings A and B are such that A.Equals(B), then
// they will return the same hash code.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode()
{
- return Marvin.ComputeHash32(ref Unsafe.As<char, byte>(ref _firstChar), _stringLength * 2, Marvin.DefaultSeed);
+ ulong seed = Marvin.DefaultSeed;
+ return Marvin.ComputeHash32(ref Unsafe.As<char, byte>(ref _firstChar), _stringLength * 2, (uint)seed, (uint)(seed >> 32));
}
// Gets a hash code for this string and this comparison. If strings A and B and comparison C are such
// that string.Equals(A, B, C), then they will return the same hash code with this comparison C.
public int GetHashCode(StringComparison comparisonType) => StringComparer.FromComparison(comparisonType).GetHashCode(this);
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ internal int GetHashCodeOrdinalIgnoreCase()
+ {
+ ulong seed = Marvin.DefaultSeed;
+ return Marvin.ComputeHash32OrdinalIgnoreCase(ref _firstChar, _stringLength, (uint)seed, (uint)(seed >> 32));
+ }
+
// Use this if and only if 'Denial of Service' attacks are not a concern (i.e. never used for free-form user input),
// or are otherwise mitigated
internal unsafe int GetNonRandomizedHashCode()