Skip to content

Commit a7f68b8

Browse files
authored
Use Unsafe.BitCast in System.Array (#116404)
1 parent c160acf commit a7f68b8

File tree

1 file changed

+8
-8
lines changed
  • src/libraries/System.Private.CoreLib/src/System

1 file changed

+8
-8
lines changed

src/libraries/System.Private.CoreLib/src/System/Array.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,31 +1513,31 @@ public static unsafe int IndexOf<T>(T[] array, T value, int startIndex, int coun
15131513
{
15141514
int result = SpanHelpers.IndexOfValueType(
15151515
ref Unsafe.Add(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetArrayDataReference(array)), startIndex),
1516-
Unsafe.As<T, byte>(ref value),
1516+
Unsafe.BitCast<T, byte>(value),
15171517
count);
15181518
return (result >= 0 ? startIndex : 0) + result;
15191519
}
15201520
else if (sizeof(T) == sizeof(short))
15211521
{
15221522
int result = SpanHelpers.IndexOfValueType(
15231523
ref Unsafe.Add(ref Unsafe.As<T, short>(ref MemoryMarshal.GetArrayDataReference(array)), startIndex),
1524-
Unsafe.As<T, short>(ref value),
1524+
Unsafe.BitCast<T, short>(value),
15251525
count);
15261526
return (result >= 0 ? startIndex : 0) + result;
15271527
}
15281528
else if (sizeof(T) == sizeof(int))
15291529
{
15301530
int result = SpanHelpers.IndexOfValueType(
15311531
ref Unsafe.Add(ref Unsafe.As<T, int>(ref MemoryMarshal.GetArrayDataReference(array)), startIndex),
1532-
Unsafe.As<T, int>(ref value),
1532+
Unsafe.BitCast<T, int>(value),
15331533
count);
15341534
return (result >= 0 ? startIndex : 0) + result;
15351535
}
15361536
else if (sizeof(T) == sizeof(long))
15371537
{
15381538
int result = SpanHelpers.IndexOfValueType(
15391539
ref Unsafe.Add(ref Unsafe.As<T, long>(ref MemoryMarshal.GetArrayDataReference(array)), startIndex),
1540-
Unsafe.As<T, long>(ref value),
1540+
Unsafe.BitCast<T, long>(value),
15411541
count);
15421542
return (result >= 0 ? startIndex : 0) + result;
15431543
}
@@ -1758,7 +1758,7 @@ public static unsafe int LastIndexOf<T>(T[] array, T value, int startIndex, int
17581758
int endIndex = startIndex - count + 1;
17591759
int result = SpanHelpers.LastIndexOfValueType(
17601760
ref Unsafe.Add(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetArrayDataReference(array)), endIndex),
1761-
Unsafe.As<T, byte>(ref value),
1761+
Unsafe.BitCast<T, byte>(value),
17621762
count);
17631763

17641764
return (result >= 0 ? endIndex : 0) + result;
@@ -1768,7 +1768,7 @@ ref Unsafe.Add(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetArrayDataReference(ar
17681768
int endIndex = startIndex - count + 1;
17691769
int result = SpanHelpers.LastIndexOfValueType(
17701770
ref Unsafe.Add(ref Unsafe.As<T, short>(ref MemoryMarshal.GetArrayDataReference(array)), endIndex),
1771-
Unsafe.As<T, short>(ref value),
1771+
Unsafe.BitCast<T, short>(value),
17721772
count);
17731773

17741774
return (result >= 0 ? endIndex : 0) + result;
@@ -1778,7 +1778,7 @@ ref Unsafe.Add(ref Unsafe.As<T, short>(ref MemoryMarshal.GetArrayDataReference(a
17781778
int endIndex = startIndex - count + 1;
17791779
int result = SpanHelpers.LastIndexOfValueType(
17801780
ref Unsafe.Add(ref Unsafe.As<T, int>(ref MemoryMarshal.GetArrayDataReference(array)), endIndex),
1781-
Unsafe.As<T, int>(ref value),
1781+
Unsafe.BitCast<T, int>(value),
17821782
count);
17831783

17841784
return (result >= 0 ? endIndex : 0) + result;
@@ -1788,7 +1788,7 @@ ref Unsafe.Add(ref Unsafe.As<T, int>(ref MemoryMarshal.GetArrayDataReference(arr
17881788
int endIndex = startIndex - count + 1;
17891789
int result = SpanHelpers.LastIndexOfValueType(
17901790
ref Unsafe.Add(ref Unsafe.As<T, long>(ref MemoryMarshal.GetArrayDataReference(array)), endIndex),
1791-
Unsafe.As<T, long>(ref value),
1791+
Unsafe.BitCast<T, long>(value),
17921792
count);
17931793

17941794
return (result >= 0 ? endIndex : 0) + result;

0 commit comments

Comments
 (0)