From: Ahson Khan Date: Wed, 11 Apr 2018 13:43:10 +0000 (-0700) Subject: Add GetPinnableReference back to Span and ReadOnlySpan (#17504) X-Git-Tag: accepted/tizen/unified/20190422.045933~2358 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2998fdfa360805e3e71695120c54e76f14becbc5;p=platform%2Fupstream%2Fcoreclr.git Add GetPinnableReference back to Span and ReadOnlySpan (#17504) --- diff --git a/src/mscorlib/shared/System/ReadOnlySpan.Fast.cs b/src/mscorlib/shared/System/ReadOnlySpan.Fast.cs index 9bf3f21..38d62dc 100644 --- a/src/mscorlib/shared/System/ReadOnlySpan.Fast.cs +++ b/src/mscorlib/shared/System/ReadOnlySpan.Fast.cs @@ -150,6 +150,13 @@ namespace System } /// + /// Returns a reference to the 0th element of the Span. If the Span is empty, returns null reference. + /// It can be used for pinning and is required to support the use of span within a fixed statement. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public unsafe ref readonly T GetPinnableReference() => ref (_length != 0) ? ref _pointer.Value : ref Unsafe.AsRef(null); + + /// /// Copies the contents of this read-only span into destination span. If the source /// and destinations overlap, this method behaves as if the original values in /// a temporary location before the destination is overwritten. diff --git a/src/mscorlib/shared/System/Span.Fast.cs b/src/mscorlib/shared/System/Span.Fast.cs index 0ae1922..131694b 100644 --- a/src/mscorlib/shared/System/Span.Fast.cs +++ b/src/mscorlib/shared/System/Span.Fast.cs @@ -155,6 +155,13 @@ namespace System } /// + /// Returns a reference to the 0th element of the Span. If the Span is empty, returns null reference. + /// It can be used for pinning and is required to support the use of span within a fixed statement. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public unsafe ref T GetPinnableReference() => ref (_length != 0) ? ref _pointer.Value : ref Unsafe.AsRef(null); + + /// /// Clears the contents of this span. /// [MethodImpl(MethodImplOptions.AggressiveInlining)]