| 12345678910111213141516171819202122232425 |
- // Licensed to the .NET Foundation under one or more agreements.
- // The .NET Foundation licenses this file to you under the MIT license.
- // See the LICENSE file in the project root for more information.
- using System.Runtime.Serialization;
- namespace System.Collections.Generic
- {
- // NonRandomizedStringEqualityComparer is the comparer used by default with the Dictionary<string,...>
- // We use NonRandomizedStringEqualityComparer as default comparer as it doesnt use the randomized string hashing which
- // keeps the performance not affected till we hit collision threshold and then we switch to the comparer which is using
- // randomized string hashing.
- [Serializable] // Required for compatibility with .NET Core 2.0 as we exposed the NonRandomizedStringEqualityComparer inside the serialization blob
- // Needs to be public to support binary serialization compatibility
- public sealed class NonRandomizedStringEqualityComparer : EqualityComparer<string>
- {
- internal static new IEqualityComparer<string> Default { get; } = new NonRandomizedStringEqualityComparer();
- private NonRandomizedStringEqualityComparer() { }
- public sealed override bool Equals(string x, string y) => string.Equals(x, y);
- public sealed override int GetHashCode(string obj) => obj?.GetNonRandomizedHashCode() ?? 0;
- }
- }
|