diff options
author | Stephen Toub <stoub@microsoft.com> | 2018-12-06 16:11:49 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-06 16:11:49 -0500 |
commit | 4ea2c295ac521272af399580006c55d295782b5a (patch) | |
tree | df4c5f1fcf30c65092d2f10532900949ecac07cf | |
parent | 5786b4b607038417a51c2990f7c3db4990126ef7 (diff) | |
download | coreclr-4ea2c295ac521272af399580006c55d295782b5a.tar.gz coreclr-4ea2c295ac521272af399580006c55d295782b5a.tar.bz2 coreclr-4ea2c295ac521272af399580006c55d295782b5a.zip |
Use Span instead of manual copy in MetadataImport.GetUserString (#21405)
* Use Span instead of manual copy in MetadataImport.GetUserString
* Address PR feedback
-rw-r--r-- | src/System.Private.CoreLib/src/System/Reflection/MdImport.cs | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/src/System.Private.CoreLib/src/System/Reflection/MdImport.cs b/src/System.Private.CoreLib/src/System/Reflection/MdImport.cs index a159745f6a..dffc8fafb2 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/MdImport.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/MdImport.cs @@ -394,20 +394,9 @@ namespace System.Reflection int length; _GetUserString(m_metadataImport2, mdToken, &name, out length); - if (name == null) - return null; - - char[] c = new char[length]; - for (int i = 0; i < c.Length; i++) - { -#if ALIGN_ACCESS - c[i] = (char)Marshal.ReadInt16( (IntPtr) (((char*)name) + i) ); -#else - c[i] = ((char*)name)[i]; -#endif - } - - return new string(c); + return name != null ? + new string((char*)name, 0, length) : + null; } [MethodImplAttribute(MethodImplOptions.InternalCall)] |