Skip to content

Commit

Permalink
Remove dead code on targets that don't support System.Half
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Jan 31, 2022
1 parent 403b028 commit f77139d
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/Dependencies/Collections/Internal/ArraySortHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
using System.Runtime.InteropServices;
#endif

#if !NET5_0_OR_GREATER
using Half = System.Single;
#endif

namespace Microsoft.CodeAnalysis.Collections.Internal
{
#region ArraySortHelper for single arrays
Expand Down Expand Up @@ -304,9 +300,12 @@ public static void Sort(SegmentedArraySegment<T> keys, IComparer<T>? comparer)
// For floating-point, do a pre-pass to move all NaNs to the beginning
// so that we can do an optimized comparison as part of the actual sort
// on the remainder of the values.
if (typeof(T) == typeof(double) ||
typeof(T) == typeof(float) ||
typeof(T) == typeof(Half))
if (typeof(T) == typeof(double)
|| typeof(T) == typeof(float)
#if NET
|| typeof(T) == typeof(Half)
#endif
)
{
int nanLeft = SegmentedArraySortUtils.MoveNansToFront(keys, default(Span<byte>));
if (nanLeft == keys.Length)
Expand Down Expand Up @@ -619,8 +618,10 @@ private static bool LessThan(ref T left, ref T right)
return (float)(object)left < (float)(object)right ? true : false;
if (typeof(T) == typeof(double))
return (double)(object)left < (double)(object)right ? true : false;
#if NET
if (typeof(T) == typeof(Half))
return (Half)(object)left < (Half)(object)right ? true : false;
#endif
return left.CompareTo(right) < 0 ? true : false;
}

Expand Down Expand Up @@ -651,8 +652,10 @@ private static bool GreaterThan(ref T left, ref T right)
return (float)(object)left > (float)(object)right ? true : false;
if (typeof(T) == typeof(double))
return (double)(object)left > (double)(object)right ? true : false;
#if NET
if (typeof(T) == typeof(Half))
return (Half)(object)left > (Half)(object)right ? true : false;
#endif
return left.CompareTo(right) > 0 ? true : false;
}
}
Expand Down Expand Up @@ -902,9 +905,12 @@ public static void Sort(SegmentedArraySegment<TKey> keys, Span<TValue> values, I
// For floating-point, do a pre-pass to move all NaNs to the beginning
// so that we can do an optimized comparison as part of the actual sort
// on the remainder of the values.
if (typeof(TKey) == typeof(double) ||
typeof(TKey) == typeof(float) ||
typeof(TKey) == typeof(Half))
if (typeof(TKey) == typeof(double)
|| typeof(TKey) == typeof(float)
#if NET
|| typeof(TKey) == typeof(Half)
#endif
)
{
int nanLeft = SegmentedArraySortUtils.MoveNansToFront(keys, values);
if (nanLeft == keys.Length)
Expand Down Expand Up @@ -1169,8 +1175,10 @@ private static bool LessThan(ref TKey left, ref TKey right)
return (float)(object)left < (float)(object)right ? true : false;
if (typeof(TKey) == typeof(double))
return (double)(object)left < (double)(object)right ? true : false;
#if NET
if (typeof(TKey) == typeof(Half))
return (Half)(object)left < (Half)(object)right ? true : false;
#endif
return left.CompareTo(right) < 0 ? true : false;
}

Expand Down Expand Up @@ -1201,8 +1209,10 @@ private static bool GreaterThan(ref TKey left, ref TKey right)
return (float)(object)left > (float)(object)right ? true : false;
if (typeof(TKey) == typeof(double))
return (double)(object)left > (double)(object)right ? true : false;
#if NET
if (typeof(TKey) == typeof(Half))
return (Half)(object)left > (Half)(object)right ? true : false;
#endif
return left.CompareTo(right) > 0 ? true : false;
}
}
Expand Down Expand Up @@ -1230,9 +1240,12 @@ public static int MoveNansToFront<TKey, TValue>(SegmentedArraySegment<TKey> keys

for (int i = 0; i < keys.Length; i++)
{
if ((typeof(TKey) == typeof(double) && double.IsNaN((double)(object)keys[i])) ||
(typeof(TKey) == typeof(float) && float.IsNaN((float)(object)keys[i])) ||
(typeof(TKey) == typeof(Half) && Half.IsNaN((Half)(object)keys[i])))
if ((typeof(TKey) == typeof(double) && double.IsNaN((double)(object)keys[i]))
|| (typeof(TKey) == typeof(float) && float.IsNaN((float)(object)keys[i]))
#if NET
|| (typeof(TKey) == typeof(Half) && Half.IsNaN((Half)(object)keys[i]))
#endif
)
{
TKey temp = keys[left];
keys[left] = keys[i];
Expand Down

0 comments on commit f77139d

Please sign in to comment.