Skip to content

Commit 38aa769

Browse files
authored
Avoid some Unsafe.As (#118655)
1 parent ed9a505 commit 38aa769

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public Span<T> Span
284284
{
285285
// Special-case string since it's the most common for ROM<char>.
286286

287-
refToReturn = ref Unsafe.As<char, T>(ref Unsafe.As<string>(tmpObject).GetRawStringData());
287+
refToReturn = ref Unsafe.As<char, T>(ref ((string)tmpObject).GetRawStringData());
288288
lengthOfUnderlyingSpan = Unsafe.As<string>(tmpObject).Length;
289289
}
290290
else if (RuntimeHelpers.ObjectHasComponentSize(tmpObject))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public ReadOnlySpan<T> Span
206206
{
207207
// Special-case string since it's the most common for ROM<char>.
208208

209-
refToReturn = ref Unsafe.As<char, T>(ref Unsafe.As<string>(tmpObject).GetRawStringData());
209+
refToReturn = ref Unsafe.As<char, T>(ref ((string)tmpObject).GetRawStringData());
210210
lengthOfUnderlyingSpan = Unsafe.As<string>(tmpObject).Length;
211211
}
212212
else if (RuntimeHelpers.ObjectHasComponentSize(tmpObject))

src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/Helpers/AhoCorasickNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public readonly bool TryGetChild(char c, out int index)
4141

4242
if (children.GetType() == typeof(int[]))
4343
{
44-
int[] table = Unsafe.As<int[]>(children);
44+
int[] table = (int[])children;
4545
if (c < (uint)table.Length)
4646
{
4747
index = table[c];

src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ private static string JoinCore<T>(ReadOnlySpan<char> separator, IEnumerable<T> v
924924
{
925925
if (values.GetType() == typeof(List<string?>)) // avoid accidentally bypassing a derived type's reimplementation of IEnumerable<T>
926926
{
927-
return JoinCore(separator, CollectionsMarshal.AsSpan(Unsafe.As<List<string?>>(values)));
927+
return JoinCore(separator, CollectionsMarshal.AsSpan((List<string?>)values));
928928
}
929929

930930
if (values is string?[] valuesArray)

0 commit comments

Comments
 (0)