The JIT is not able to inline the current implementation of Unsafe.AsRef because of it has type mismatch on return. Change the the corelib Span to call Unsafe.As instead since fixing the type mismatch is not easy in the internal corelib version of Unsafe.AsRef.
if (length < 0)
ThrowHelper.ThrowArgumentOutOfRangeException();
- _pointer = new ByReference<T>(ref Unsafe.AsRef<T>(pointer));
+ _pointer = new ByReference<T>(ref Unsafe.As<byte, T>(ref *(byte*)pointer));
_length = length;
}
throw new InvalidOperationException();
}
- /// <summary>
- /// Reinterprets the given location as a reference to a value of type<typeparamref name="T"/>.
- /// </summary>
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ref T AsRef<T>(void * source)
- {
- // The body of this function will be replaced by the EE with unsafe code!!!
- // See getILIntrinsicImplementationForUnsafe for how this happens.
- throw new InvalidOperationException();
- }
-
/// <summary>
/// Reinterprets the given reference as a reference to a value of type <typeparamref name="TTo"/>.
/// </summary>
if (length < 0)
ThrowHelper.ThrowArgumentOutOfRangeException();
- _pointer = new ByReference<T>(ref Unsafe.AsRef<T>(pointer));
+ _pointer = new ByReference<T>(ref Unsafe.As<byte, T>(ref *(byte*)pointer));
_length = length;
}
methInfo->options = (CorInfoOptions)0;
return true;
}
- else if ((tk == MscorlibBinder::GetMethod(METHOD__UNSAFE__AS_REF)->GetMemberDef()) ||
- (tk == MscorlibBinder::GetMethod(METHOD__UNSAFE__BYREF_AS)->GetMemberDef()))
-
+ else if (tk == MscorlibBinder::GetMethod(METHOD__UNSAFE__BYREF_AS)->GetMemberDef())
{
// Return the argument that was passed in.
static const BYTE ilcode[] = { CEE_LDARG_0, CEE_RET };
DEFINE_CLASS(UNSAFE, CompilerServices, Unsafe)
DEFINE_METHOD(UNSAFE, AS_POINTER, AsPointer, NoSig)
DEFINE_METHOD(UNSAFE, SIZEOF, SizeOf, NoSig)
-DEFINE_METHOD(UNSAFE, AS_REF, AsRef, NoSig)
DEFINE_METHOD(UNSAFE, BYREF_AS, As, NoSig)
DEFINE_METHOD(UNSAFE, BYREF_ADD, Add, NoSig)
DEFINE_METHOD(UNSAFE, BYREF_ARE_SAME, AreSame, NoSig)