From 6932b4fb20d332e2dd372b661f5b6cfcaa0b5273 Mon Sep 17 00:00:00 2001 From: Andrew J Said Date: Thu, 9 Nov 2023 14:25:19 +0000 Subject: [PATCH 1/2] Use comparison instead of specialized class --- .../src/System.Collections.Immutable.csproj | 4 --- .../Collections/Frozen/FrozenDictionary.cs | 20 +++++-------- ...rozenDictionary_LeftJustifiedSingleChar.cs | 6 +++- ..._LeftJustifiedSingleCharCaseInsensitive.cs | 29 ------------------ ...FrozenDictionary_LeftJustifiedSubstring.cs | 6 +++- ...y_LeftJustifiedSubstringCaseInsensitive.cs | 30 ------------------- ...ozenDictionary_RightJustifiedSingleChar.cs | 6 +++- ...RightJustifiedSingleCharCaseInsensitive.cs | 29 ------------------ ...rozenDictionary_RightJustifiedSubstring.cs | 6 +++- ..._RightJustifiedSubstringCaseInsensitive.cs | 30 ------------------- 10 files changed, 28 insertions(+), 138 deletions(-) delete mode 100644 src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSingleCharCaseInsensitive.cs delete mode 100644 src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSubstringCaseInsensitive.cs delete mode 100644 src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSingleCharCaseInsensitive.cs delete mode 100644 src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSubstringCaseInsensitive.cs diff --git a/src/libraries/System.Collections.Immutable/src/System.Collections.Immutable.csproj b/src/libraries/System.Collections.Immutable/src/System.Collections.Immutable.csproj index 32f97b137e678..87cf0520f8616 100644 --- a/src/libraries/System.Collections.Immutable/src/System.Collections.Immutable.csproj +++ b/src/libraries/System.Collections.Immutable/src/System.Collections.Immutable.csproj @@ -67,10 +67,6 @@ The System.Collections.Immutable library is built-in as part of the shared frame - - - - diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenDictionary.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenDictionary.cs index cfde792bfc71f..b8084c19d67e7 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenDictionary.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenDictionary.cs @@ -192,15 +192,13 @@ private static FrozenDictionary CreateFromDictionary { if (analysis.HashCount == 1) { - frozenDictionary = analysis.IgnoreCase - ? new OrdinalStringFrozenDictionary_RightJustifiedSingleCharCaseInsensitive(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex) - : new OrdinalStringFrozenDictionary_RightJustifiedSingleChar(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex); + var comparison = analysis.IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; + frozenDictionary = new OrdinalStringFrozenDictionary_RightJustifiedSingleChar(keys, values, stringComparer, comparison, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex); } else { - frozenDictionary = analysis.IgnoreCase - ? new OrdinalStringFrozenDictionary_RightJustifiedSubstringCaseInsensitive(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount) - : new OrdinalStringFrozenDictionary_RightJustifiedSubstring(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount); + var comparison = analysis.IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; + frozenDictionary = new OrdinalStringFrozenDictionary_RightJustifiedSubstring(keys, values, stringComparer, comparison, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount); } } } @@ -217,15 +215,13 @@ private static FrozenDictionary CreateFromDictionary { if (analysis.HashCount == 1) { - frozenDictionary = analysis.IgnoreCase - ? new OrdinalStringFrozenDictionary_LeftJustifiedSingleCharCaseInsensitive(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex) - : new OrdinalStringFrozenDictionary_LeftJustifiedSingleChar(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex); + var comparison = analysis.IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; + frozenDictionary = new OrdinalStringFrozenDictionary_LeftJustifiedSingleChar(keys, values, stringComparer, comparison, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex); } else { - frozenDictionary = analysis.IgnoreCase - ? new OrdinalStringFrozenDictionary_LeftJustifiedSubstringCaseInsensitive(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount) - : new OrdinalStringFrozenDictionary_LeftJustifiedSubstring(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount); + var comparison = analysis.IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; + frozenDictionary = new OrdinalStringFrozenDictionary_LeftJustifiedSubstring(keys, values, stringComparer, comparison, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount); } } } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSingleChar.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSingleChar.cs index b2bb0bb97b1a6..52d797e91cfbc 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSingleChar.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSingleChar.cs @@ -7,15 +7,19 @@ namespace System.Collections.Frozen { internal sealed class OrdinalStringFrozenDictionary_LeftJustifiedSingleChar : OrdinalStringFrozenDictionary { + private StringComparison _comparison; + internal OrdinalStringFrozenDictionary_LeftJustifiedSingleChar( string[] keys, TValue[] values, IEqualityComparer comparer, + StringComparison comparison, int minimumLength, int maximumLengthDiff, int hashIndex) : base(keys, values, comparer, minimumLength, maximumLengthDiff, hashIndex, 1) { + _comparison = comparison; } // This override is necessary to force the jit to emit the code in such a way that it @@ -23,7 +27,7 @@ internal OrdinalStringFrozenDictionary_LeftJustifiedSingleChar( // remove this, or you'll tank performance. private protected override ref readonly TValue GetValueRefOrNullRefCore(string key) => ref base.GetValueRefOrNullRefCore(key); - private protected override bool Equals(string? x, string? y) => string.Equals(x, y); + private protected override bool Equals(string? x, string? y) => string.Equals(x, y, _comparison); private protected override int GetHashCode(string s) => s[HashIndex]; } } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSingleCharCaseInsensitive.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSingleCharCaseInsensitive.cs deleted file mode 100644 index 2bebf7e04c18f..0000000000000 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSingleCharCaseInsensitive.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Generic; - -namespace System.Collections.Frozen -{ - internal sealed class OrdinalStringFrozenDictionary_LeftJustifiedSingleCharCaseInsensitive : OrdinalStringFrozenDictionary - { - internal OrdinalStringFrozenDictionary_LeftJustifiedSingleCharCaseInsensitive( - string[] keys, - TValue[] values, - IEqualityComparer comparer, - int minimumLength, - int maximumLengthDiff, - int hashIndex) - : base(keys, values, comparer, minimumLength, maximumLengthDiff, hashIndex, 1) - { - } - - // This override is necessary to force the jit to emit the code in such a way that it - // avoids virtual dispatch overhead when calling the Equals/GetHashCode methods. Don't - // remove this, or you'll tank performance. - private protected override ref readonly TValue GetValueRefOrNullRefCore(string key) => ref base.GetValueRefOrNullRefCore(key); - - private protected override bool Equals(string? x, string? y) => StringComparer.OrdinalIgnoreCase.Equals(x, y); - private protected override int GetHashCode(string s) => s[HashIndex]; - } -} diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSubstring.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSubstring.cs index 2812dde4f1027..533b5403330b4 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSubstring.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSubstring.cs @@ -7,16 +7,20 @@ namespace System.Collections.Frozen { internal sealed class OrdinalStringFrozenDictionary_LeftJustifiedSubstring : OrdinalStringFrozenDictionary { + private StringComparison _comparison; + internal OrdinalStringFrozenDictionary_LeftJustifiedSubstring( string[] keys, TValue[] values, IEqualityComparer comparer, + StringComparison comparison, int minimumLength, int maximumLengthDiff, int hashIndex, int hashCount) : base(keys, values, comparer, minimumLength, maximumLengthDiff, hashIndex, hashCount) { + _comparison = comparison; } // This override is necessary to force the jit to emit the code in such a way that it @@ -24,7 +28,7 @@ internal OrdinalStringFrozenDictionary_LeftJustifiedSubstring( // remove this, or you'll tank performance. private protected override ref readonly TValue GetValueRefOrNullRefCore(string key) => ref base.GetValueRefOrNullRefCore(key); - private protected override bool Equals(string? x, string? y) => string.Equals(x, y); + private protected override bool Equals(string? x, string? y) => string.Equals(x, y, _comparison); private protected override int GetHashCode(string s) => Hashing.GetHashCodeOrdinal(s.AsSpan(HashIndex, HashCount)); } } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSubstringCaseInsensitive.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSubstringCaseInsensitive.cs deleted file mode 100644 index 0aec2fbe80473..0000000000000 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSubstringCaseInsensitive.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Generic; - -namespace System.Collections.Frozen -{ - internal sealed class OrdinalStringFrozenDictionary_LeftJustifiedSubstringCaseInsensitive : OrdinalStringFrozenDictionary - { - internal OrdinalStringFrozenDictionary_LeftJustifiedSubstringCaseInsensitive( - string[] keys, - TValue[] values, - IEqualityComparer comparer, - int minimumLength, - int maximumLengthDiff, - int hashIndex, - int hashCount) - : base(keys, values, comparer, minimumLength, maximumLengthDiff, hashIndex, hashCount) - { - } - - // This override is necessary to force the jit to emit the code in such a way that it - // avoids virtual dispatch overhead when calling the Equals/GetHashCode methods. Don't - // remove this, or you'll tank performance. - private protected override ref readonly TValue GetValueRefOrNullRefCore(string key) => ref base.GetValueRefOrNullRefCore(key); - - private protected override bool Equals(string? x, string? y) => StringComparer.OrdinalIgnoreCase.Equals(x, y); - private protected override int GetHashCode(string s) => Hashing.GetHashCodeOrdinal(s.AsSpan(HashIndex, HashCount)); - } -} diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSingleChar.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSingleChar.cs index cb7ae5fda7b4d..a8e6241a1a935 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSingleChar.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSingleChar.cs @@ -7,15 +7,19 @@ namespace System.Collections.Frozen { internal sealed class OrdinalStringFrozenDictionary_RightJustifiedSingleChar : OrdinalStringFrozenDictionary { + private StringComparison _comparison; + internal OrdinalStringFrozenDictionary_RightJustifiedSingleChar( string[] keys, TValue[] values, IEqualityComparer comparer, + StringComparison comparison, int minimumLength, int maximumLengthDiff, int hashIndex) : base(keys, values, comparer, minimumLength, maximumLengthDiff, hashIndex, 1) { + _comparison = comparison; } // This override is necessary to force the jit to emit the code in such a way that it @@ -23,7 +27,7 @@ internal OrdinalStringFrozenDictionary_RightJustifiedSingleChar( // remove this, or you'll tank performance. private protected override ref readonly TValue GetValueRefOrNullRefCore(string key) => ref base.GetValueRefOrNullRefCore(key); - private protected override bool Equals(string? x, string? y) => string.Equals(x, y); + private protected override bool Equals(string? x, string? y) => string.Equals(x, y, _comparison); private protected override int GetHashCode(string s) => s[s.Length + HashIndex]; } } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSingleCharCaseInsensitive.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSingleCharCaseInsensitive.cs deleted file mode 100644 index b60fb38ae3240..0000000000000 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSingleCharCaseInsensitive.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Generic; - -namespace System.Collections.Frozen -{ - internal sealed class OrdinalStringFrozenDictionary_RightJustifiedSingleCharCaseInsensitive : OrdinalStringFrozenDictionary - { - internal OrdinalStringFrozenDictionary_RightJustifiedSingleCharCaseInsensitive( - string[] keys, - TValue[] values, - IEqualityComparer comparer, - int minimumLength, - int maximumLengthDiff, - int hashIndex) - : base(keys, values, comparer, minimumLength, maximumLengthDiff, hashIndex, 1) - { - } - - // This override is necessary to force the jit to emit the code in such a way that it - // avoids virtual dispatch overhead when calling the Equals/GetHashCode methods. Don't - // remove this, or you'll tank performance. - private protected override ref readonly TValue GetValueRefOrNullRefCore(string key) => ref base.GetValueRefOrNullRefCore(key); - - private protected override bool Equals(string? x, string? y) => StringComparer.OrdinalIgnoreCase.Equals(x, y); - private protected override int GetHashCode(string s) => s[s.Length + HashIndex]; - } -} diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSubstring.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSubstring.cs index cd8fe0602ef7b..5ea1465eb35f7 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSubstring.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSubstring.cs @@ -7,16 +7,20 @@ namespace System.Collections.Frozen { internal sealed class OrdinalStringFrozenDictionary_RightJustifiedSubstring : OrdinalStringFrozenDictionary { + private StringComparison _comparison; + internal OrdinalStringFrozenDictionary_RightJustifiedSubstring( string[] keys, TValue[] values, IEqualityComparer comparer, + StringComparison comparison, int minimumLength, int maximumLengthDiff, int hashIndex, int hashCount) : base(keys, values, comparer, minimumLength, maximumLengthDiff, hashIndex, hashCount) { + _comparison = comparison; } // This override is necessary to force the jit to emit the code in such a way that it @@ -24,7 +28,7 @@ internal OrdinalStringFrozenDictionary_RightJustifiedSubstring( // remove this, or you'll tank performance. private protected override ref readonly TValue GetValueRefOrNullRefCore(string key) => ref base.GetValueRefOrNullRefCore(key); - private protected override bool Equals(string? x, string? y) => string.Equals(x, y); + private protected override bool Equals(string? x, string? y) => string.Equals(x, y, _comparison); private protected override int GetHashCode(string s) => Hashing.GetHashCodeOrdinal(s.AsSpan(s.Length + HashIndex, HashCount)); } } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSubstringCaseInsensitive.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSubstringCaseInsensitive.cs deleted file mode 100644 index 117d2f329ccf4..0000000000000 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSubstringCaseInsensitive.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Generic; - -namespace System.Collections.Frozen -{ - internal sealed class OrdinalStringFrozenDictionary_RightJustifiedSubstringCaseInsensitive : OrdinalStringFrozenDictionary - { - internal OrdinalStringFrozenDictionary_RightJustifiedSubstringCaseInsensitive( - string[] keys, - TValue[] values, - IEqualityComparer comparer, - int minimumLength, - int maximumLengthDiff, - int hashIndex, - int hashCount) - : base(keys, values, comparer, minimumLength, maximumLengthDiff, hashIndex, hashCount) - { - } - - // This override is necessary to force the jit to emit the code in such a way that it - // avoids virtual dispatch overhead when calling the Equals/GetHashCode methods. Don't - // remove this, or you'll tank performance. - private protected override ref readonly TValue GetValueRefOrNullRefCore(string key) => ref base.GetValueRefOrNullRefCore(key); - - private protected override bool Equals(string? x, string? y) => StringComparer.OrdinalIgnoreCase.Equals(x, y); - private protected override int GetHashCode(string s) => Hashing.GetHashCodeOrdinal(s.AsSpan(s.Length + HashIndex, HashCount)); - } -} From eda35d29b39582820aa92589d0bcc5c20a940bf4 Mon Sep 17 00:00:00 2001 From: Andrew J Said Date: Thu, 9 Nov 2023 23:55:08 +0000 Subject: [PATCH 2/2] Use comparer instead of comparison --- .../System/Collections/Frozen/FrozenDictionary.cs | 12 ++++-------- ...StringFrozenDictionary_LeftJustifiedSingleChar.cs | 6 +----- ...lStringFrozenDictionary_LeftJustifiedSubstring.cs | 6 +----- ...tringFrozenDictionary_RightJustifiedSingleChar.cs | 6 +----- ...StringFrozenDictionary_RightJustifiedSubstring.cs | 6 +----- 5 files changed, 8 insertions(+), 28 deletions(-) diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenDictionary.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenDictionary.cs index b8084c19d67e7..0a173c278172f 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenDictionary.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenDictionary.cs @@ -192,13 +192,11 @@ private static FrozenDictionary CreateFromDictionary { if (analysis.HashCount == 1) { - var comparison = analysis.IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; - frozenDictionary = new OrdinalStringFrozenDictionary_RightJustifiedSingleChar(keys, values, stringComparer, comparison, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex); + frozenDictionary = new OrdinalStringFrozenDictionary_RightJustifiedSingleChar(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex); } else { - var comparison = analysis.IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; - frozenDictionary = new OrdinalStringFrozenDictionary_RightJustifiedSubstring(keys, values, stringComparer, comparison, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount); + frozenDictionary = new OrdinalStringFrozenDictionary_RightJustifiedSubstring(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount); } } } @@ -215,13 +213,11 @@ private static FrozenDictionary CreateFromDictionary { if (analysis.HashCount == 1) { - var comparison = analysis.IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; - frozenDictionary = new OrdinalStringFrozenDictionary_LeftJustifiedSingleChar(keys, values, stringComparer, comparison, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex); + frozenDictionary = new OrdinalStringFrozenDictionary_LeftJustifiedSingleChar(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex); } else { - var comparison = analysis.IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; - frozenDictionary = new OrdinalStringFrozenDictionary_LeftJustifiedSubstring(keys, values, stringComparer, comparison, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount); + frozenDictionary = new OrdinalStringFrozenDictionary_LeftJustifiedSubstring(keys, values, stringComparer, analysis.MinimumLength, analysis.MaximumLengthDiff, analysis.HashIndex, analysis.HashCount); } } } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSingleChar.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSingleChar.cs index 52d797e91cfbc..4f80f9a47a4d4 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSingleChar.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSingleChar.cs @@ -7,19 +7,15 @@ namespace System.Collections.Frozen { internal sealed class OrdinalStringFrozenDictionary_LeftJustifiedSingleChar : OrdinalStringFrozenDictionary { - private StringComparison _comparison; - internal OrdinalStringFrozenDictionary_LeftJustifiedSingleChar( string[] keys, TValue[] values, IEqualityComparer comparer, - StringComparison comparison, int minimumLength, int maximumLengthDiff, int hashIndex) : base(keys, values, comparer, minimumLength, maximumLengthDiff, hashIndex, 1) { - _comparison = comparison; } // This override is necessary to force the jit to emit the code in such a way that it @@ -27,7 +23,7 @@ internal OrdinalStringFrozenDictionary_LeftJustifiedSingleChar( // remove this, or you'll tank performance. private protected override ref readonly TValue GetValueRefOrNullRefCore(string key) => ref base.GetValueRefOrNullRefCore(key); - private protected override bool Equals(string? x, string? y) => string.Equals(x, y, _comparison); + private protected override bool Equals(string? x, string? y) => Comparer.Equals(x, y); private protected override int GetHashCode(string s) => s[HashIndex]; } } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSubstring.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSubstring.cs index 533b5403330b4..6b2e1b169195d 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSubstring.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_LeftJustifiedSubstring.cs @@ -7,20 +7,16 @@ namespace System.Collections.Frozen { internal sealed class OrdinalStringFrozenDictionary_LeftJustifiedSubstring : OrdinalStringFrozenDictionary { - private StringComparison _comparison; - internal OrdinalStringFrozenDictionary_LeftJustifiedSubstring( string[] keys, TValue[] values, IEqualityComparer comparer, - StringComparison comparison, int minimumLength, int maximumLengthDiff, int hashIndex, int hashCount) : base(keys, values, comparer, minimumLength, maximumLengthDiff, hashIndex, hashCount) { - _comparison = comparison; } // This override is necessary to force the jit to emit the code in such a way that it @@ -28,7 +24,7 @@ internal OrdinalStringFrozenDictionary_LeftJustifiedSubstring( // remove this, or you'll tank performance. private protected override ref readonly TValue GetValueRefOrNullRefCore(string key) => ref base.GetValueRefOrNullRefCore(key); - private protected override bool Equals(string? x, string? y) => string.Equals(x, y, _comparison); + private protected override bool Equals(string? x, string? y) => Comparer.Equals(x, y); private protected override int GetHashCode(string s) => Hashing.GetHashCodeOrdinal(s.AsSpan(HashIndex, HashCount)); } } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSingleChar.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSingleChar.cs index a8e6241a1a935..2aa540cf62f99 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSingleChar.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSingleChar.cs @@ -7,19 +7,15 @@ namespace System.Collections.Frozen { internal sealed class OrdinalStringFrozenDictionary_RightJustifiedSingleChar : OrdinalStringFrozenDictionary { - private StringComparison _comparison; - internal OrdinalStringFrozenDictionary_RightJustifiedSingleChar( string[] keys, TValue[] values, IEqualityComparer comparer, - StringComparison comparison, int minimumLength, int maximumLengthDiff, int hashIndex) : base(keys, values, comparer, minimumLength, maximumLengthDiff, hashIndex, 1) { - _comparison = comparison; } // This override is necessary to force the jit to emit the code in such a way that it @@ -27,7 +23,7 @@ internal OrdinalStringFrozenDictionary_RightJustifiedSingleChar( // remove this, or you'll tank performance. private protected override ref readonly TValue GetValueRefOrNullRefCore(string key) => ref base.GetValueRefOrNullRefCore(key); - private protected override bool Equals(string? x, string? y) => string.Equals(x, y, _comparison); + private protected override bool Equals(string? x, string? y) => Comparer.Equals(x, y); private protected override int GetHashCode(string s) => s[s.Length + HashIndex]; } } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSubstring.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSubstring.cs index 5ea1465eb35f7..3df40a7dd83dc 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSubstring.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/String/OrdinalStringFrozenDictionary_RightJustifiedSubstring.cs @@ -7,20 +7,16 @@ namespace System.Collections.Frozen { internal sealed class OrdinalStringFrozenDictionary_RightJustifiedSubstring : OrdinalStringFrozenDictionary { - private StringComparison _comparison; - internal OrdinalStringFrozenDictionary_RightJustifiedSubstring( string[] keys, TValue[] values, IEqualityComparer comparer, - StringComparison comparison, int minimumLength, int maximumLengthDiff, int hashIndex, int hashCount) : base(keys, values, comparer, minimumLength, maximumLengthDiff, hashIndex, hashCount) { - _comparison = comparison; } // This override is necessary to force the jit to emit the code in such a way that it @@ -28,7 +24,7 @@ internal OrdinalStringFrozenDictionary_RightJustifiedSubstring( // remove this, or you'll tank performance. private protected override ref readonly TValue GetValueRefOrNullRefCore(string key) => ref base.GetValueRefOrNullRefCore(key); - private protected override bool Equals(string? x, string? y) => string.Equals(x, y, _comparison); + private protected override bool Equals(string? x, string? y) => Comparer.Equals(x, y); private protected override int GetHashCode(string s) => Hashing.GetHashCodeOrdinal(s.AsSpan(s.Length + HashIndex, HashCount)); } }