Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed Mar 20, 2024
1 parent 0d69258 commit 1bdb1f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ internal static unsafe class CastHelpers
[DebuggerHidden]
private static ref byte Unbox(void* toTypeHnd, object obj)
{
// this will throw NullReferenceException if obj is null, attributed to the user code, as expected.
// This will throw NullReferenceException if obj is null.
if (RuntimeHelpers.GetMethodTable(obj) == toTypeHnd)
return ref obj.GetRawData();

Expand All @@ -387,9 +387,10 @@ private static void ThrowArrayMismatchException()
}

[DebuggerHidden]
private static ref object? LdelemaRef(object?[]? array, nint index, void* type)
private static ref object? LdelemaRef(object?[] array, nint index, void* type)
{
if ((nuint)index >= (uint)array!.Length)
// This will throw NullReferenceException if array is null.
if ((nuint)index >= (uint)array.Length)
ThrowIndexOutOfRangeException();

Debug.Assert(index >= 0);
Expand All @@ -403,9 +404,10 @@ private static void ThrowArrayMismatchException()
}

[DebuggerHidden]
private static void StelemRef(object?[]? array, nint index, object? obj)
private static void StelemRef(object?[] array, nint index, object? obj)
{
if ((nuint)index >= (uint)array!.Length)
// This will throw NullReferenceException if array is null.
if ((nuint)index >= (uint)array.Length)
ThrowIndexOutOfRangeException();

Debug.Assert(index >= 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,12 @@ private static unsafe void ThrowArrayMismatchException(object?[] array)
//

[RuntimeExport("RhpLdelemaRef")]
public static unsafe ref object? LdelemaRef(object?[]? array, nint index, MethodTable* elementType)
public static unsafe ref object? LdelemaRef(object?[] array, nint index, MethodTable* elementType)
{
Debug.Assert(array is null || array.GetMethodTable()->IsArray, "first argument must be an array");

#if INPLACE_RUNTIME
// This will throw NullReferenceException if obj is null.
if ((nuint)index >= (uint)array.Length)
ThrowIndexOutOfRangeException(array);

Expand All @@ -789,12 +790,13 @@ private static unsafe void ThrowArrayMismatchException(object?[] array)
}

[RuntimeExport("RhpStelemRef")]
public static unsafe void StelemRef(object?[]? array, nint index, object? obj)
public static unsafe void StelemRef(object?[] array, nint index, object? obj)
{
// This is supported only on arrays
Debug.Assert(array is null || array.GetMethodTable()->IsArray, "first argument must be an array");

#if INPLACE_RUNTIME
// This will throw NullReferenceException if obj is null.
if ((nuint)index >= (uint)array.Length)
ThrowIndexOutOfRangeException(array);

Expand Down Expand Up @@ -857,15 +859,14 @@ private static unsafe void StelemRef_Helper(ref object? element, MethodTable* el
private static unsafe void StelemRef_Helper_NoCacheLookup(ref object? element, MethodTable* elementType, object obj)
{
object? castedObj = IsInstanceOfAny_NoCacheLookup(elementType, obj);
if (castedObj != null)
if (castedObj == null)
{
InternalCalls.RhpAssignRef(ref element, obj);
return;
// Throw the array type mismatch exception defined by the classlib, using the input array's
// MethodTable* to find the correct classlib.
throw elementType->GetClasslibException(ExceptionIDs.ArrayTypeMismatch);
}

// Throw the array type mismatch exception defined by the classlib, using the input array's
// MethodTable* to find the correct classlib.
throw elementType->GetClasslibException(ExceptionIDs.ArrayTypeMismatch);
InternalCalls.RhpAssignRef(ref element, obj);
}

private static unsafe object IsInstanceOfArray(MethodTable* pTargetType, object obj)
Expand Down

0 comments on commit 1bdb1f6

Please sign in to comment.