Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unnecessary lazy init in StructuralComparisons #101344

Merged
merged 2 commits into from
Apr 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ namespace System.Collections
{
public static class StructuralComparisons
{
private static volatile IComparer? s_StructuralComparer;
private static volatile IEqualityComparer? s_StructuralEqualityComparer;
public static IComparer StructuralComparer => System.Collections.StructuralComparer.s_instance;

public static IComparer StructuralComparer => s_StructuralComparer ??= new StructuralComparer();

public static IEqualityComparer StructuralEqualityComparer => s_StructuralEqualityComparer ??= new StructuralEqualityComparer();
public static IEqualityComparer StructuralEqualityComparer => System.Collections.StructuralEqualityComparer.s_instance;
}

internal sealed class StructuralEqualityComparer : IEqualityComparer
{
internal static readonly StructuralEqualityComparer s_instance = new();

public new bool Equals(object? x, object? y)
{
if (x != null)
Expand Down Expand Up @@ -58,6 +57,8 @@ public int GetHashCode(object obj)

internal sealed class StructuralComparer : IComparer
{
internal static readonly StructuralComparer s_instance = new();

public int Compare(object? x, object? y)
{
if (x == null) return y == null ? 0 : -1;
Expand Down
Loading