@@ -19,20 +19,21 @@ public DataRange(long startPoint, long length)
19
19
20
20
public int Compare ( DataRange x , DataRange y )
21
21
{
22
- if ( ReferenceEquals ( x , y ) )
23
- {
24
- return 0 ;
25
- }
26
-
27
- if ( ReferenceEquals ( null , y ) )
28
- {
29
- return 1 ;
30
- }
31
-
32
- if ( ReferenceEquals ( null , x ) )
33
- {
34
- return - 1 ;
35
- }
22
+ // 由于 DataRange 从引用类型修改为值类型,这就导致原本调用 ReferenceEquals 的代码为傻逼代码,注释掉,避免无用的装箱判断不相等
23
+ //if (ReferenceEquals(x, y))
24
+ //{
25
+ // return 0;
26
+ //}
27
+
28
+ //if (ReferenceEquals(null, y))
29
+ //{
30
+ // return 1;
31
+ //}
32
+
33
+ //if (ReferenceEquals(null, x))
34
+ //{
35
+ // return -1;
36
+ //}
36
37
37
38
return x . StartPoint . CompareTo ( y . StartPoint ) ;
38
39
}
@@ -66,15 +67,16 @@ public static bool TryMerge(DataRange a, DataRange b, out DataRange newDataRange
66
67
67
68
public bool Equals ( DataRange other )
68
69
{
69
- if ( ReferenceEquals ( null , other ) )
70
- {
71
- return false ;
72
- }
70
+ // 由于 DataRange 从引用类型修改为值类型,这就导致原本调用 ReferenceEquals 的代码为傻逼代码,注释掉,避免无用的装箱判断不相等
71
+ //if (ReferenceEquals(null, other))
72
+ //{
73
+ // return false;
74
+ //}
73
75
74
- if ( ReferenceEquals ( this , other ) )
75
- {
76
- return true ;
77
- }
76
+ // if (ReferenceEquals(this, other))
77
+ // {
78
+ // return true;
79
+ // }
78
80
79
81
return StartPoint == other . StartPoint && Length == other . Length ;
80
82
}
@@ -86,11 +88,6 @@ public override bool Equals(object? obj)
86
88
return false ;
87
89
}
88
90
89
- if ( ReferenceEquals ( this , obj ) )
90
- {
91
- return true ;
92
- }
93
-
94
91
if ( obj . GetType ( ) != GetType ( ) )
95
92
{
96
93
return false ;
@@ -103,7 +100,11 @@ public override int GetHashCode()
103
100
{
104
101
unchecked
105
102
{
103
+ #if NETCOREAPP3_1_OR_GREATER
104
+ return HashCode . Combine ( StartPoint , Length ) ;
105
+ #else
106
106
return ( StartPoint . GetHashCode ( ) * 397 ) ^ Length . GetHashCode ( ) ;
107
+ #endif
107
108
}
108
109
}
109
110
0 commit comments