Imported Upstream version 5.16.0.100

Former-commit-id: 38faa55fb9669e35e7d8448b15c25dc447f25767
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-08-07 15:19:03 +00:00
parent 0a9828183b
commit 7d7f676260
4419 changed files with 170950 additions and 90273 deletions

View File

@@ -476,12 +476,52 @@ namespace System {
#if MONO
// Converts a Span into an int
public static int ToInt32(ReadOnlySpan<byte> value)
public static unsafe int ToInt32(ReadOnlySpan<byte> value)
{
if (value.Length < sizeof(int))
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
return Unsafe.ReadUnaligned<int>(ref value.DangerousGetPinnableReference());
fixed (byte* bytesPtr = &value.GetPinnableReference())
{
return Unsafe.ReadUnaligned<int>(bytesPtr);
}
}
// Convert a Span into a uint
[CLSCompliant(false)]
public static unsafe uint ToUInt32(ReadOnlySpan<byte> value)
{
if (value.Length < sizeof(uint))
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
fixed (byte* bytesPtr = &value.GetPinnableReference())
{
return Unsafe.ReadUnaligned<uint>(bytesPtr);
}
}
// Converts a Span into an unsigned long
[CLSCompliant(false)]
public static unsafe ulong ToUInt64(ReadOnlySpan<byte> value)
{
if (value.Length < sizeof(ulong))
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
fixed (byte* bytesPtr = &value.GetPinnableReference())
{
return Unsafe.ReadUnaligned<ulong>(bytesPtr);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe int SingleToInt32Bits(float value)
{
return *((int*)&value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe float Int32BitsToSingle(int value)
{
return *((float*)&value);
}
#endif
}