@KrzysztofCwalina @jkotas @adamsitnik @atsushikan
Contract's methods where changed recently from throwing to calling ThrowHelper's methods.
The older JITs don't recognize those throw helpers as never return methods and keep the call in the hot area. That affects the portable Span.
This is how RequiresInRange looked before the change:
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void RequiresInRange(int start, uint length)
{
if ((uint)start >= length)
{
throw NewArgumentOutOfRangeException();
}
}
Now it does this:
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void RequiresInRange(int start, uint length)
{
if ((uint)start >= length)
{
ThrowHelper.ThrowArgumentOutOfRangeException();
}
}
This method compiled on .NET Framework 4.6.1..
[MethodImpl(MethodImplOptions.NoInlining)]
static byte SpanIndexer(Span<byte> slice, int index)
{
return slice[index];
}
generates the following code:
sub rsp,28h
mov eax,dword ptr [rcx+10h]
cmp edx,eax
jb 000007FE980138A8
; next 3 lines should be located in the cold area at the end of the method
call 000007FE98012390
mov rcx,rax
call 000007FEF77B1C00
mov rax,qword ptr [rcx]
mov rcx,qword ptr [rcx+8]
movsxd rdx,edx
add rax,rcx
movzx eax,byte ptr [rax+rdx]
add rsp,28h
ret