[mono] Use InlineArrayAttribute for ArgumentData and StackAllocatedByRefs (#88149)
authorAleksey Kliger (λgeek) <alklig@microsoft.com>
Thu, 29 Jun 2023 13:44:15 +0000 (09:44 -0400)
committerGitHub <noreply@github.com>
Thu, 29 Jun 2023 13:44:15 +0000 (09:44 -0400)
* [mono] Use InlineArrayAttribute for ArgumentData and StackAllocatedByRefs

   Mono supports InlineArray

* Apply suggestions from code review

* Expose two more uses of InlineArray in ParamsArray.cs

---------

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
src/libraries/System.Private.CoreLib/src/System/ParamsArray.cs
src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs

index a4b5fd9..d1bf55b 100644 (file)
@@ -12,8 +12,6 @@ using System.Runtime.CompilerServices;
 
 namespace System
 {
-#if CORECLR || NATIVEAOT
-
     [InlineArray(Length)]
     internal struct TwoObjects
     {
@@ -46,33 +44,4 @@ namespace System
             this[2] = arg2;
         }
     }
-
-#else
-
-    internal struct TwoObjects
-    {
-        internal object? Arg0;
-        private object? _arg1;
-
-        public TwoObjects(object? arg0, object? arg1)
-        {
-            Arg0 = arg0;
-            _arg1 = arg1;
-        }
-    }
-
-    internal struct ThreeObjects
-    {
-        internal object? Arg0;
-        private object? _arg1;
-        private object? _arg2;
-
-        public ThreeObjects(object? arg0, object? arg1, object? arg2)
-        {
-            Arg0 = arg0;
-            _arg1 = arg1;
-            _arg2 = arg2;
-        }
-    }
-#endif
 }
index a43181e..2a8349a 100644 (file)
@@ -274,19 +274,11 @@ namespace System.Reflection
 
         internal const int MaxStackAllocArgCount = 4;
 
-#if CORECLR
         [InlineArray(MaxStackAllocArgCount)]
-#endif
         private protected struct ArgumentData<T>
         {
             private T _arg0;
-#if !CORECLR
-#pragma warning disable CA1823, CS0169, IDE0051, IDE0044 // accessed via 'CheckArguments' ref arithmetic
-            private T _arg1;
-            private T _arg2;
-            private T _arg3;
-#pragma warning restore CA1823, CS0169, IDE0051, IDE0044
-#endif
+
             [UnscopedRef]
             public Span<T> AsSpan(int length)
             {
@@ -308,19 +300,10 @@ namespace System.Reflection
         }
 
         // Helper struct to avoid intermediate IntPtr[] allocation and RegisterForGCReporting in calls to the native reflection stack.
-#if CORECLR
         [InlineArray(MaxStackAllocArgCount)]
-#endif
         private protected ref struct StackAllocatedByRefs
         {
             internal ref byte _arg0;
-#if !CORECLR
-#pragma warning disable CA1823, CS0169, IDE0051 // accessed via 'CheckArguments' ref arithmetic
-            private ref byte _arg1;
-            private ref byte _arg2;
-            private ref byte _arg3;
-#pragma warning restore CA1823, CS0169, IDE0051
-#endif
         }
 #endif
         }