Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ec93425

Browse files
committedApr 23, 2024·
Undo dictionary changes
1 parent 1de83fd commit ec93425

File tree

2 files changed

+8
-29
lines changed

2 files changed

+8
-29
lines changed
 

‎src/libraries/System.Private.CoreLib/src/System/AppContext.cs

+1-17
Original file line numberDiff line numberDiff line change
@@ -152,26 +152,10 @@ internal static unsafe void Setup(char** pNames, char** pValues, int count)
152152
}
153153
}
154154

155-
private sealed class AppContextKeyComparer : IEqualityComparer<string?>
156-
{
157-
public bool Equals(string? x, string? y) => string.Equals(x, y);
158-
159-
public int GetHashCode(string? obj)
160-
{
161-
Debug.Assert(obj != null, "This implementation is only called from first-party collection types that guarantee non-null parameters.");
162-
return obj.GetNonRandomizedHashCode();
163-
}
164-
}
165-
166155
internal static unsafe void Setup(char** pNames, uint** pNameLengths, char** pValues, uint** pValueLengths, int count)
167156
{
168157
Debug.Assert(s_dataStore == null, "s_dataStore is not expected to be inited before Setup is called");
169-
// HACK: Use a special comparer that does not pull in all the dependencies that
170-
// the default BCL string comparers pull in
171-
IEqualityComparer<string?> comparer = new AppContextKeyComparer();
172-
// HACK: Use a special version of the Dictionary constructor that does not pull in a
173-
// large amount of extra code in order to instantiate this dictionary
174-
s_dataStore = new Dictionary<string, object?>(count, comparer, true);
158+
s_dataStore = new Dictionary<string, object?>(count);
175159
for (int i = 0; i < count; i++)
176160
{
177161
s_dataStore.Add(new string(pNames[i], 0, (int)pNameLengths[i]), new string(pValues[i], 0, (int)pValueLengths[i]));

‎src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs

+7-12
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ public Dictionary(int capacity) : this(capacity, null) { }
4343

4444
public Dictionary(IEqualityComparer<TKey>? comparer) : this(0, comparer) { }
4545

46-
public Dictionary(int capacity, IEqualityComparer<TKey>? comparer) : this(0, comparer, false) { }
47-
48-
internal Dictionary(int capacity, IEqualityComparer<TKey>? comparer, bool useProvidedComparer)
46+
public Dictionary(int capacity, IEqualityComparer<TKey>? comparer)
4947
{
5048
if (capacity < 0)
5149
{
@@ -68,16 +66,13 @@ internal Dictionary(int capacity, IEqualityComparer<TKey>? comparer, bool usePro
6866
{
6967
_comparer = comparer ?? EqualityComparer<TKey>.Default;
7068

71-
if (!useProvidedComparer)
69+
// Special-case EqualityComparer<string>.Default, StringComparer.Ordinal, and StringComparer.OrdinalIgnoreCase.
70+
// We use a non-randomized comparer for improved perf, falling back to a randomized comparer if the
71+
// hash buckets become unbalanced.
72+
if (typeof(TKey) == typeof(string) &&
73+
NonRandomizedStringEqualityComparer.GetStringComparer(_comparer!) is IEqualityComparer<string> stringComparer)
7274
{
73-
// Special-case EqualityComparer<string>.Default, StringComparer.Ordinal, and StringComparer.OrdinalIgnoreCase.
74-
// We use a non-randomized comparer for improved perf, falling back to a randomized comparer if the
75-
// hash buckets become unbalanced.
76-
if (typeof(TKey) == typeof(string) &&
77-
NonRandomizedStringEqualityComparer.GetStringComparer(_comparer!) is IEqualityComparer<string> stringComparer)
78-
{
79-
_comparer = (IEqualityComparer<TKey>)stringComparer;
80-
}
75+
_comparer = (IEqualityComparer<TKey>)stringComparer;
8176
}
8277
}
8378
else if (comparer is not null && // first check for null to avoid forcing default comparer instantiation unnecessarily

0 commit comments

Comments
 (0)
Please sign in to comment.