From: Ahson Ahmed Khan Date: Thu, 2 Mar 2017 18:13:13 +0000 (-0800) Subject: Removing ref T Span.GetItem and updating Indexer to return ref (dotnet/coreclr#9787) X-Git-Tag: submit/tizen/20210909.063632~11030^2~7874 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fae3c583e3be78c16afda97ec08e20db0372d21d;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Removing ref T Span.GetItem and updating Indexer to return ref (dotnet/coreclr#9787) Commit migrated from https://github.com/dotnet/coreclr/commit/7e4f1b5720bea994ea76c7ec8f90e02b0739ec62 --- 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); } ///