@@ -7,70 +7,66 @@ namespace System.Collections
7
7
{
8
8
public static class StructuralComparisons
9
9
{
10
- private static volatile IComparer ? s_StructuralComparer ;
11
- private static volatile IEqualityComparer ? s_StructuralEqualityComparer ;
10
+ private static readonly Comparer s_comparer = new ( ) ;
12
11
13
- public static IComparer StructuralComparer => s_StructuralComparer ??= new StructuralComparer ( ) ;
12
+ public static IComparer StructuralComparer => s_comparer ;
14
13
15
- public static IEqualityComparer StructuralEqualityComparer => s_StructuralEqualityComparer ??= new StructuralEqualityComparer ( ) ;
16
- }
14
+ public static IEqualityComparer StructuralEqualityComparer => s_comparer ;
17
15
18
- internal sealed class StructuralEqualityComparer : IEqualityComparer
19
- {
20
- public new bool Equals ( object ? x , object ? y )
16
+ private sealed class Comparer : IEqualityComparer , IComparer
21
17
{
22
- if ( x != null )
18
+ public new bool Equals ( object ? x , object ? y )
23
19
{
24
- IStructuralEquatable ? seObj = x as IStructuralEquatable ;
25
-
26
- if ( seObj != null )
20
+ if ( x != null )
27
21
{
28
- return seObj . Equals ( y , this ) ;
29
- }
22
+ IStructuralEquatable ? seObj = x as IStructuralEquatable ;
30
23
31
- if ( y != null )
32
- {
33
- return x . Equals ( y ) ;
34
- }
35
- else
36
- {
37
- return false ;
24
+ if ( seObj != null )
25
+ {
26
+ return seObj . Equals ( y , this ) ;
27
+ }
28
+
29
+ if ( y != null )
30
+ {
31
+ return x . Equals ( y ) ;
32
+ }
33
+ else
34
+ {
35
+ return false ;
36
+ }
38
37
}
38
+ if ( y != null ) return false ;
39
+ return true ;
39
40
}
40
- if ( y != null ) return false ;
41
- return true ;
42
- }
43
41
44
- public int GetHashCode ( object obj )
45
- {
46
- if ( obj == null ) return 0 ;
42
+ public int GetHashCode ( object obj )
43
+ {
44
+ if ( obj == null ) return 0 ;
47
45
48
- IStructuralEquatable ? seObj = obj as IStructuralEquatable ;
46
+ IStructuralEquatable ? seObj = obj as IStructuralEquatable ;
49
47
50
- if ( seObj != null )
51
- {
52
- return seObj . GetHashCode ( this ) ;
48
+ if ( seObj != null )
49
+ {
50
+ return seObj . GetHashCode ( this ) ;
51
+ }
52
+
53
+ return obj . GetHashCode ( ) ;
53
54
}
54
55
55
- return obj . GetHashCode ( ) ;
56
- }
57
- }
56
+ public int Compare ( object ? x , object ? y )
57
+ {
58
+ if ( x == null ) return y == null ? 0 : - 1 ;
59
+ if ( y == null ) return 1 ;
58
60
59
- internal sealed class StructuralComparer : IComparer
60
- {
61
- public int Compare ( object ? x , object ? y )
62
- {
63
- if ( x == null ) return y == null ? 0 : - 1 ;
64
- if ( y == null ) return 1 ;
61
+ IStructuralComparable ? scX = x as IStructuralComparable ;
65
62
66
- IStructuralComparable ? scX = x as IStructuralComparable ;
63
+ if ( scX != null )
64
+ {
65
+ return scX . CompareTo ( y , this ) ;
66
+ }
67
67
68
- if ( scX != null )
69
- {
70
- return scX . CompareTo ( y , this ) ;
68
+ return Comparer < object > . Default . Compare ( x , y ) ;
71
69
}
72
-
73
- return Comparer < object > . Default . Compare ( x , y ) ;
74
70
}
75
71
}
76
72
}
0 commit comments