summaryrefslogtreecommitdiff
path: root/src/System.Private.CoreLib/shared/System/ReadOnlySpan.Fast.cs
diff options
context:
space:
mode:
authorJan Kotas <jkotas@microsoft.com>2018-10-15 21:39:18 -0700
committerGitHub <noreply@github.com>2018-10-15 21:39:18 -0700
commitd3ed7cb8da830657c376d4adb2862bc3c09cfef7 (patch)
tree4760e9a64feb639c74bea3125dc9c5b815b63528 /src/System.Private.CoreLib/shared/System/ReadOnlySpan.Fast.cs
parent85ed652fef5f1dec7c532bd4963dd3cde0199211 (diff)
downloadcoreclr-d3ed7cb8da830657c376d4adb2862bc3c09cfef7.tar.gz
coreclr-d3ed7cb8da830657c376d4adb2862bc3c09cfef7.tar.bz2
coreclr-d3ed7cb8da830657c376d4adb2862bc3c09cfef7.zip
Optimize Span.GetPinnableReference (#20428)
* Optimize Span.GetPinnableReference * CR feedback
Diffstat (limited to 'src/System.Private.CoreLib/shared/System/ReadOnlySpan.Fast.cs')
-rw-r--r--src/System.Private.CoreLib/shared/System/ReadOnlySpan.Fast.cs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/System.Private.CoreLib/shared/System/ReadOnlySpan.Fast.cs b/src/System.Private.CoreLib/shared/System/ReadOnlySpan.Fast.cs
index 4fb039a0fc..8ba8fd66b6 100644
--- a/src/System.Private.CoreLib/shared/System/ReadOnlySpan.Fast.cs
+++ b/src/System.Private.CoreLib/shared/System/ReadOnlySpan.Fast.cs
@@ -153,7 +153,13 @@ namespace System
/// 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