Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ public ref readonly T this[int index]
/// It can be used for pinning and is required to support the use of span within a fixed statement.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public unsafe ref readonly T GetPinnableReference() => ref (_length != 0) ? ref _pointer.Value : ref Unsafe.AsRef<T>(null);
public unsafe ref readonly T GetPinnableReference()
{
// Ensure that the native code has just one forward branch that is predicted-not-taken.
ref T ret = ref Unsafe.AsRef<T>(null);
if (_length != 0) ret = ref _pointer.Value;
return ref ret;
}

/// <summary>
/// Copies the contents of this read-only span into destination span. If the source
Expand Down
8 changes: 7 additions & 1 deletion src/System.Private.CoreLib/shared/System/Span.Fast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,13 @@ public ref T this[int index]
/// It can be used for pinning and is required to support the use of span within a fixed statement.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public unsafe ref T GetPinnableReference() => ref (_length != 0) ? ref _pointer.Value : ref Unsafe.AsRef<T>(null);
public unsafe ref T GetPinnableReference()
{
// Ensure that the native code has just one forward branch that is predicted-not-taken.
ref T ret = ref Unsafe.AsRef<T>(null);
if (_length != 0) ret = ref _pointer.Value;
return ref ret;
}

/// <summary>
/// Clears the contents of this span.
Expand Down