Eliminate a bounds check in `NumberBuffer` (#81039)
authorxtqqczze <45661989+xtqqczze@users.noreply.github.com>
Mon, 30 Jan 2023 01:22:17 +0000 (01:22 +0000)
committerGitHub <noreply@github.com>
Mon, 30 Jan 2023 01:22:17 +0000 (20:22 -0500)
* Eliminate a bounds check in `NumberBuffer`

* Add AggressiveInlining

src/libraries/System.Private.CoreLib/src/System/Number.NumberBuffer.cs

index df5908f..22a2076 100644 (file)
@@ -4,6 +4,7 @@
 using System.Diagnostics;
 using System.Text;
 using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
 
 namespace System
 {
@@ -82,10 +83,11 @@ namespace System
             }
 #pragma warning restore CA1822
 
+            [MethodImpl(MethodImplOptions.AggressiveInlining)]
             public byte* GetDigitsPointer()
             {
                 // This is safe to do since we are a ref struct
-                return (byte*)(Unsafe.AsPointer(ref Digits[0]));
+                return (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(Digits));
             }
 
             //