/// <exception cref="System.IndexOutOfRangeException">
/// Thrown when index less than 0 or index greater than or equal to Length
/// </exception>
-
- // TODO: https://github.com/dotnet/corefx/issues/13681
- // Until we get over the hurdle of C# 7 tooling, this indexer will return "T" and have a setter rather than a "ref T". (The doc comments
- // continue to reflect the original intent of returning "ref T")
- public T this[int index]
+ public ref T this[int index]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
if ((uint)index >= (uint)_length)
ThrowHelper.ThrowIndexOutOfRangeException();
- return Unsafe.Add(ref _pointer.Value, index);
+ return ref Unsafe.Add(ref _pointer.Value, index);
}
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- set
- {
- if ((uint)index >= (uint)_length)
- ThrowHelper.ThrowIndexOutOfRangeException();
-
- Unsafe.Add(ref _pointer.Value, index) = value;
- }
- }
-
- /// <summary>
- /// Returns a reference to specified element of the Span.
- /// </summary>
- /// <param name="index"></param>
- /// <returns></returns>
- /// <exception cref="System.IndexOutOfRangeException">
- /// Thrown when index less than 0 or index greater than or equal to Length
- /// </exception>
-
- // TODO: https://github.com/dotnet/corefx/issues/13681
- // Until we get over the hurdle of C# 7 tooling, this temporary method will simulate the intended "ref T" indexer for those
- // who need bypass the workaround for performance.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ref T GetItem(int index)
- {
- if ((uint)index >= ((uint)_length))
- ThrowHelper.ThrowIndexOutOfRangeException();
-
- return ref Unsafe.Add(ref _pointer.Value, index);
}
/// <summary>