From cd183b66e2fb2f833a6fc222b3fa5919b1388cee Mon Sep 17 00:00:00 2001 From: simplejackcoder Date: Mon, 25 Mar 2019 04:44:26 +0000 Subject: [PATCH 1/3] GetPinnableReference on String.cs --- src/System.Private.CoreLib/shared/System/String.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/System.Private.CoreLib/shared/System/String.cs b/src/System.Private.CoreLib/shared/System/String.cs index 10f75225c00d..aca410ee06f2 100644 --- a/src/System.Private.CoreLib/shared/System/String.cs +++ b/src/System.Private.CoreLib/shared/System/String.cs @@ -472,6 +472,11 @@ public static bool IsNullOrWhiteSpace(string value) return true; } + /// + /// Returns a reference to the first element of the String. If the string is null, an access will throw a NullReferenceException. + /// + public ref readonly char GetPinnableReference() => ref _firstChar; + internal ref char GetRawStringData() => ref _firstChar; // Helper for encodings so they can talk to our buffer directly From 471232c05dd7a750444e40bcbfdbd5f59bfe112a Mon Sep 17 00:00:00 2001 From: simplejackcoder Date: Mon, 25 Mar 2019 06:33:55 +0000 Subject: [PATCH 2/3] Add attributes for debugger and performance --- src/System.Private.CoreLib/shared/System/String.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/System.Private.CoreLib/shared/System/String.cs b/src/System.Private.CoreLib/shared/System/String.cs index aca410ee06f2..97f72ef23c5a 100644 --- a/src/System.Private.CoreLib/shared/System/String.cs +++ b/src/System.Private.CoreLib/shared/System/String.cs @@ -11,6 +11,8 @@ using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; +using EditorBrowsableAttribute = System.ComponentModel.EditorBrowsableAttribute; +using EditorBrowsableState = System.ComponentModel.EditorBrowsableState; using Internal.Runtime.CompilerServices; namespace System @@ -475,6 +477,8 @@ public static bool IsNullOrWhiteSpace(string value) /// /// Returns a reference to the first element of the String. If the string is null, an access will throw a NullReferenceException. /// + [EditorBrowsable(EditorBrowsableState.Never)] + [NonVersionable] public ref readonly char GetPinnableReference() => ref _firstChar; internal ref char GetRawStringData() => ref _firstChar; From aeea302319aa78724d80699cedf1acedbce005f7 Mon Sep 17 00:00:00 2001 From: simplejackcoder Date: Mon, 25 Mar 2019 07:39:17 +0000 Subject: [PATCH 3/3] Update based on feedback --- src/System.Private.CoreLib/shared/System/String.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/String.cs b/src/System.Private.CoreLib/shared/System/String.cs index 97f72ef23c5a..177d5e1f17b1 100644 --- a/src/System.Private.CoreLib/shared/System/String.cs +++ b/src/System.Private.CoreLib/shared/System/String.cs @@ -11,8 +11,6 @@ using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; -using EditorBrowsableAttribute = System.ComponentModel.EditorBrowsableAttribute; -using EditorBrowsableState = System.ComponentModel.EditorBrowsableState; using Internal.Runtime.CompilerServices; namespace System @@ -477,7 +475,7 @@ public static bool IsNullOrWhiteSpace(string value) /// /// Returns a reference to the first element of the String. If the string is null, an access will throw a NullReferenceException. /// - [EditorBrowsable(EditorBrowsableState.Never)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [NonVersionable] public ref readonly char GetPinnableReference() => ref _firstChar;