Skip to content

Commit adae699

Browse files
committed
去掉傻逼代码
1 parent 89278a7 commit adae699

File tree

1 file changed

+28
-27
lines changed
  • src/dotnetCampus.FileDownloader/Utils/BreakpointResumptionTransmissions

1 file changed

+28
-27
lines changed

src/dotnetCampus.FileDownloader/Utils/BreakpointResumptionTransmissions/DataRange.cs

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,21 @@ public DataRange(long startPoint, long length)
1919

2020
public int Compare(DataRange x, DataRange y)
2121
{
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+
//}
3637

3738
return x.StartPoint.CompareTo(y.StartPoint);
3839
}
@@ -66,15 +67,16 @@ public static bool TryMerge(DataRange a, DataRange b, out DataRange newDataRange
6667

6768
public bool Equals(DataRange other)
6869
{
69-
if (ReferenceEquals(null, other))
70-
{
71-
return false;
72-
}
70+
// 由于 DataRange 从引用类型修改为值类型,这就导致原本调用 ReferenceEquals 的代码为傻逼代码,注释掉,避免无用的装箱判断不相等
71+
//if (ReferenceEquals(null, other))
72+
//{
73+
// return false;
74+
//}
7375

74-
if (ReferenceEquals(this, other))
75-
{
76-
return true;
77-
}
76+
//if (ReferenceEquals(this, other))
77+
//{
78+
// return true;
79+
//}
7880

7981
return StartPoint == other.StartPoint && Length == other.Length;
8082
}
@@ -86,11 +88,6 @@ public override bool Equals(object? obj)
8688
return false;
8789
}
8890

89-
if (ReferenceEquals(this, obj))
90-
{
91-
return true;
92-
}
93-
9491
if (obj.GetType() != GetType())
9592
{
9693
return false;
@@ -103,7 +100,11 @@ public override int GetHashCode()
103100
{
104101
unchecked
105102
{
103+
#if NETCOREAPP3_1_OR_GREATER
104+
return HashCode.Combine(StartPoint, Length);
105+
#else
106106
return (StartPoint.GetHashCode() * 397) ^ Length.GetHashCode();
107+
#endif
107108
}
108109
}
109110

0 commit comments

Comments
 (0)