From fae3c583e3be78c16afda97ec08e20db0372d21d Mon Sep 17 00:00:00 2001 From: Ahson Ahmed Khan Date: Thu, 2 Mar 2017 10:13:13 -0800 Subject: [PATCH] Removing ref T Span.GetItem and updating Indexer to return ref (dotnet/coreclr#9787) Commit migrated from https://github.com/dotnet/coreclr/commit/7e4f1b5720bea994ea76c7ec8f90e02b0739ec62 --- src/coreclr/src/mscorlib/src/System/Span.cs | 37 ++--------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/src/coreclr/src/mscorlib/src/System/Span.cs b/src/coreclr/src/mscorlib/src/System/Span.cs index cb21853..8fa85cc 100644 --- a/src/coreclr/src/mscorlib/src/System/Span.cs +++ b/src/coreclr/src/mscorlib/src/System/Span.cs @@ -191,11 +191,7 @@ namespace System /// /// Thrown when index less than 0 or index greater than or equal to Length /// - - // 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 @@ -203,37 +199,8 @@ namespace System 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; - } - } - - /// - /// Returns a reference to specified element of the Span. - /// - /// - /// - /// - /// Thrown when index less than 0 or index greater than or equal to Length - /// - - // 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); } /// -- 2.7.4