/// <summary>A byref or a native ptr.</summary>
private readonly ByReference<T> _pointer;
/// <summary>The number of elements this ReadOnlySpan contains.</summary>
+#if PROJECTN
+ [Bound]
+#endif
private readonly int _length;
/// <summary>
/// </exception>
public T this[int index]
{
+#if PROJECTN
+ [BoundsChecking]
+ get
+ {
+ return Unsafe.Add(ref _pointer.Value, index);
+ }
+#else
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
if ((uint)index >= (uint)_length)
ThrowHelper.ThrowIndexOutOfRangeException();
-
return Unsafe.Add(ref _pointer.Value, index);
}
+#endif
}
/// <summary>
if (byteLength == 0)
return;
-#if AMD64
+#if AMD64 && CORECLR
if (byteLength > 4096) goto PInvoke;
Unsafe.InitBlockUnaligned(ref b, 0, (uint)byteLength);
return;
-#else // AMD64
- // TODO: Optimize this method on X86 machine
+#else
+ // TODO: Optimize other platforms to be on par with AMD64 CoreCLR
// Note: It's important that this switch handles lengths at least up to 22.
// See notes below near the main loop for why.
}
return;
-#endif // AMD64
+#endif
PInvoke:
RuntimeImports.RhZeroMemory(ref b, byteLength);
/// <summary>A byref or a native ptr.</summary>
private readonly ByReference<T> _pointer;
/// <summary>The number of elements this Span contains.</summary>
+#if PROJECTN
+ [Bound]
+#endif
private readonly int _length;
/// <summary>
/// </exception>
public ref T this[int index]
{
+#if PROJECTN
+ [BoundsChecking]
+ get
+ {
+ return ref Unsafe.Add(ref _pointer.Value, index);
+ }
+#else
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
if ((uint)index >= (uint)_length)
ThrowHelper.ThrowIndexOutOfRangeException();
-
return ref Unsafe.Add(ref _pointer.Value, index);
}
+#endif
}
/// <summary>