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

Use architecture independent code paths in Array #108449

Merged
merged 2 commits into from
Oct 5, 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
79 changes: 31 additions & 48 deletions src/libraries/System.Private.CoreLib/src/System/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -916,29 +916,25 @@ public static int BinarySearch(Array array, int index, int length, object? value
result = GenericBinarySearch<ushort>(array, adjustedIndex, length, value);
break;
case CorElementType.ELEMENT_TYPE_I4:
#if TARGET_32BIT
case CorElementType.ELEMENT_TYPE_I:
#endif
result = GenericBinarySearch<int>(array, adjustedIndex, length, value);
break;
case CorElementType.ELEMENT_TYPE_U4:
#if TARGET_32BIT
case CorElementType.ELEMENT_TYPE_U:
#endif
result = GenericBinarySearch<uint>(array, adjustedIndex, length, value);
break;
case CorElementType.ELEMENT_TYPE_I8:
#if TARGET_64BIT
case CorElementType.ELEMENT_TYPE_I:
#endif
result = GenericBinarySearch<long>(array, adjustedIndex, length, value);
break;
case CorElementType.ELEMENT_TYPE_U8:
#if TARGET_64BIT
case CorElementType.ELEMENT_TYPE_U:
#endif
result = GenericBinarySearch<ulong>(array, adjustedIndex, length, value);
break;
case CorElementType.ELEMENT_TYPE_I:
if (IntPtr.Size == 4)
goto case CorElementType.ELEMENT_TYPE_I4;
goto case CorElementType.ELEMENT_TYPE_I8;
case CorElementType.ELEMENT_TYPE_U:
if (IntPtr.Size == 4)
goto case CorElementType.ELEMENT_TYPE_U4;
goto case CorElementType.ELEMENT_TYPE_U8;
case CorElementType.ELEMENT_TYPE_R4:
result = GenericBinarySearch<float>(array, adjustedIndex, length, value);
break;
Expand Down Expand Up @@ -1424,20 +1420,17 @@ public static int IndexOf(Array array, object? value, int startIndex, int count)
break;
case CorElementType.ELEMENT_TYPE_I4:
case CorElementType.ELEMENT_TYPE_U4:
#if TARGET_32BIT
case CorElementType.ELEMENT_TYPE_I:
case CorElementType.ELEMENT_TYPE_U:
#endif
result = GenericIndexOf<int>(array, value, adjustedIndex, count);
break;
case CorElementType.ELEMENT_TYPE_I8:
case CorElementType.ELEMENT_TYPE_U8:
#if TARGET_64BIT
case CorElementType.ELEMENT_TYPE_I:
case CorElementType.ELEMENT_TYPE_U:
#endif
result = GenericIndexOf<long>(array, value, adjustedIndex, count);
break;
case CorElementType.ELEMENT_TYPE_I:
case CorElementType.ELEMENT_TYPE_U:
if (IntPtr.Size == 4)
goto case CorElementType.ELEMENT_TYPE_I4;
goto case CorElementType.ELEMENT_TYPE_I8;
case CorElementType.ELEMENT_TYPE_R4:
result = GenericIndexOf<float>(array, value, adjustedIndex, count);
break;
Expand Down Expand Up @@ -1654,20 +1647,17 @@ public static int LastIndexOf(Array array, object? value, int startIndex, int co
break;
case CorElementType.ELEMENT_TYPE_I4:
case CorElementType.ELEMENT_TYPE_U4:
#if TARGET_32BIT
case CorElementType.ELEMENT_TYPE_I:
case CorElementType.ELEMENT_TYPE_U:
#endif
result = GenericLastIndexOf<int>(array, value, adjustedIndex, count);
break;
case CorElementType.ELEMENT_TYPE_I8:
case CorElementType.ELEMENT_TYPE_U8:
#if TARGET_64BIT
case CorElementType.ELEMENT_TYPE_I:
case CorElementType.ELEMENT_TYPE_U:
#endif
result = GenericLastIndexOf<long>(array, value, adjustedIndex, count);
break;
case CorElementType.ELEMENT_TYPE_I:
case CorElementType.ELEMENT_TYPE_U:
if (IntPtr.Size == 4)
goto case CorElementType.ELEMENT_TYPE_I4;
goto case CorElementType.ELEMENT_TYPE_I8;
case CorElementType.ELEMENT_TYPE_R4:
result = GenericLastIndexOf<float>(array, value, adjustedIndex, count);
break;
Expand Down Expand Up @@ -1863,22 +1853,19 @@ public static void Reverse(Array array, int index, int length)
return;
case CorElementType.ELEMENT_TYPE_I4:
case CorElementType.ELEMENT_TYPE_U4:
#if TARGET_32BIT
case CorElementType.ELEMENT_TYPE_I:
case CorElementType.ELEMENT_TYPE_U:
#endif
case CorElementType.ELEMENT_TYPE_R4:
UnsafeArrayAsSpan<int>(array, adjustedIndex, length).Reverse();
return;
case CorElementType.ELEMENT_TYPE_I8:
case CorElementType.ELEMENT_TYPE_U8:
#if TARGET_64BIT
case CorElementType.ELEMENT_TYPE_I:
case CorElementType.ELEMENT_TYPE_U:
#endif
case CorElementType.ELEMENT_TYPE_R8:
UnsafeArrayAsSpan<long>(array, adjustedIndex, length).Reverse();
return;
case CorElementType.ELEMENT_TYPE_I:
case CorElementType.ELEMENT_TYPE_U:
if (IntPtr.Size == 4)
goto case CorElementType.ELEMENT_TYPE_I4;
goto case CorElementType.ELEMENT_TYPE_I8;
case CorElementType.ELEMENT_TYPE_OBJECT:
case CorElementType.ELEMENT_TYPE_ARRAY:
case CorElementType.ELEMENT_TYPE_SZARRAY:
Expand Down Expand Up @@ -2069,29 +2056,25 @@ public static void Sort(Array keys, Array? items, int index, int length, ICompar
GenericSort<ushort>(keys, items, adjustedIndex, length);
return;
case CorElementType.ELEMENT_TYPE_I4:
#if TARGET_32BIT
case CorElementType.ELEMENT_TYPE_I:
#endif
GenericSort<int>(keys, items, adjustedIndex, length);
return;
case CorElementType.ELEMENT_TYPE_U4:
#if TARGET_32BIT
case CorElementType.ELEMENT_TYPE_U:
#endif
GenericSort<uint>(keys, items, adjustedIndex, length);
return;
case CorElementType.ELEMENT_TYPE_I8:
#if TARGET_64BIT
case CorElementType.ELEMENT_TYPE_I:
#endif
GenericSort<long>(keys, items, adjustedIndex, length);
return;
case CorElementType.ELEMENT_TYPE_U8:
#if TARGET_64BIT
case CorElementType.ELEMENT_TYPE_U:
#endif
GenericSort<ulong>(keys, items, adjustedIndex, length);
return;
case CorElementType.ELEMENT_TYPE_I:
if (IntPtr.Size == 4)
goto case CorElementType.ELEMENT_TYPE_I4;
goto case CorElementType.ELEMENT_TYPE_I8;
case CorElementType.ELEMENT_TYPE_U:
if (IntPtr.Size == 4)
goto case CorElementType.ELEMENT_TYPE_U4;
goto case CorElementType.ELEMENT_TYPE_U8;
case CorElementType.ELEMENT_TYPE_R4:
GenericSort<float>(keys, items, adjustedIndex, length);
return;
Expand Down
Loading