From f36aa7ec736735a3e92046c73d6e03029017b9fa Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Fri, 15 Mar 2024 09:16:07 -0400 Subject: [PATCH] Clean up some [InlineArray] use (#99766) * Clean up some [InlineArray] use * Remove AsSpan method --- .../System/Reflection/ConstructorInvoker.cs | 26 ++++++++-------- .../System/Reflection/DynamicInvokeInfo.cs | 19 ++---------- .../src/System/Reflection/MethodInvoker.cs | 24 +++++++-------- .../src/ActivatorUtilities.cs | 30 ++++++------------- .../System.Private.CoreLib.Shared.projitems | 5 ++-- .../src/System/IO/StreamWriter.cs | 8 ++--- .../{ParamsArray.cs => InlineArrays.cs} | 17 +++++------ .../System/Reflection/ConstructorInvoker.cs | 6 ++-- .../src/System/Reflection/MethodBase.cs | 21 +++---------- .../System/Reflection/MethodBaseInvoker.cs | 4 +-- .../src/System/Reflection/MethodInvoker.cs | 6 ++-- .../AsciiStringSearchValuesTeddyBase.cs | 8 ++--- .../Strings/Helpers/EightPackedReferences.cs | 23 -------------- .../src/System/String.Manipulation.cs | 8 ++--- .../src/System/Text/StringBuilder.cs | 8 ++--- 15 files changed, 73 insertions(+), 140 deletions(-) rename src/libraries/System.Private.CoreLib/src/System/{ParamsArray.cs => InlineArrays.cs} (63%) delete mode 100644 src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/Helpers/EightPackedReferences.cs diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs index 57e446520b2ea..52e2589b3e978 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs @@ -53,7 +53,7 @@ public object Invoke(object? arg1) ThrowForArgCountMismatch(); } - object result = _methodBaseInvoker.CreateInstanceWithFewArgs(new Span(ref arg1, _parameterCount)); + object result = _methodBaseInvoker.CreateInstanceWithFewArgs(new Span(ref arg1)); DebugAnnotations.PreviousCallContainsDebuggerStepInCode(); return result; } @@ -67,9 +67,9 @@ public object Invoke(object? arg1, object? arg2) } StackAllocatedArguments argStorage = default; - argStorage._args.Set(0, arg1); - argStorage._args.Set(1, arg2); - object result = _methodBaseInvoker.CreateInstanceWithFewArgs(argStorage._args.AsSpan(_parameterCount)); + argStorage._args[0] = arg1; + argStorage._args[1] = arg2; + object result = _methodBaseInvoker.CreateInstanceWithFewArgs(((Span)argStorage._args).Slice(0, 2)); DebugAnnotations.PreviousCallContainsDebuggerStepInCode(); return result; } @@ -83,10 +83,10 @@ public object Invoke(object? arg1, object? arg2, object? arg3) } StackAllocatedArguments argStorage = default; - argStorage._args.Set(0, arg1); - argStorage._args.Set(1, arg2); - argStorage._args.Set(2, arg3); - object result = _methodBaseInvoker.CreateInstanceWithFewArgs(argStorage._args.AsSpan(_parameterCount)); + argStorage._args[0] = arg1; + argStorage._args[1] = arg2; + argStorage._args[2] = arg3; + object result = _methodBaseInvoker.CreateInstanceWithFewArgs(((Span)argStorage._args).Slice(0, 3)); DebugAnnotations.PreviousCallContainsDebuggerStepInCode(); return result; } @@ -100,11 +100,11 @@ public object Invoke(object? arg1, object? arg2, object? arg3, object? arg4) } StackAllocatedArguments argStorage = default; - argStorage._args.Set(0, arg1); - argStorage._args.Set(1, arg2); - argStorage._args.Set(2, arg3); - argStorage._args.Set(3, arg4); - object result = _methodBaseInvoker.CreateInstanceWithFewArgs(argStorage._args.AsSpan(_parameterCount)); + argStorage._args[0] = arg1; + argStorage._args[1] = arg2; + argStorage._args[2] = arg3; + argStorage._args[3] = arg4; + object result = _methodBaseInvoker.CreateInstanceWithFewArgs(((Span)argStorage._args).Slice(0, 4)); DebugAnnotations.PreviousCallContainsDebuggerStepInCode(); return result; } diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/DynamicInvokeInfo.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/DynamicInvokeInfo.cs index 012e410885b8e..6ddac7c3d3de2 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/DynamicInvokeInfo.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/DynamicInvokeInfo.cs @@ -497,10 +497,9 @@ private unsafe ref byte InvokeWithFewArguments( object?[] parameters, BinderBundle? binderBundle, bool wrapInTargetInvocationException) { Debug.Assert(_argumentCount <= MaxStackAllocArgCount); - int argCount = _argumentCount; StackAllocatedArguments argStorage = default; - Span copyOfParameters = argStorage._args.AsSpan(argCount); + Span copyOfParameters = ((Span)argStorage._args).Slice(0, _argumentCount); StackAllocatedByRefs byrefStorage = default; #pragma warning disable CS8500 void* pByRefStorage = (ByReference*)&byrefStorage; @@ -532,10 +531,9 @@ private unsafe ref byte InvokeWithFewArguments( IntPtr methodToCall, ref byte thisArg, ref byte ret, Span parameters) { Debug.Assert(_argumentCount <= MaxStackAllocArgCount); - int argCount = _argumentCount; StackAllocatedArguments argStorage = default; - Span copyOfParameters = argStorage._args.AsSpan(argCount); + Span copyOfParameters = ((Span)argStorage._args).Slice(0, _argumentCount); StackAllocatedByRefs byrefStorage = default; #pragma warning disable CS8500 void* pByRefStorage = (ByReference*)&byrefStorage; @@ -884,19 +882,6 @@ private unsafe object ReturnTransform(ref byte byref, bool wrapInTargetInvocatio internal struct ArgumentData { private T _arg0; - - [UnscopedRef] - public Span AsSpan(int length) - { - Debug.Assert((uint)length <= MaxStackAllocArgCount); - return new Span(ref _arg0, length); - } - - public void Set(int index, T value) - { - Debug.Assert((uint)index < MaxStackAllocArgCount); - Unsafe.Add(ref _arg0, index) = value; - } } // Helper struct to avoid intermediate object[] allocation in calls to the native reflection stack. diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs index 847914850f99c..661f7f2853528 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs @@ -81,10 +81,10 @@ public static MethodInvoker Create(MethodBase method) } StackAllocatedArguments argStorage = default; - argStorage._args.Set(0, arg1); - argStorage._args.Set(1, arg2); + argStorage._args[0] = arg1; + argStorage._args[1] = arg2; - object? result = _methodBaseInvoker.InvokeDirectWithFewArgs(obj, argStorage._args.AsSpan(_parameterCount)); + object? result = _methodBaseInvoker.InvokeDirectWithFewArgs(obj, ((Span)argStorage._args).Slice(0, 2)); DebugAnnotations.PreviousCallContainsDebuggerStepInCode(); return result; } @@ -98,11 +98,11 @@ public static MethodInvoker Create(MethodBase method) } StackAllocatedArguments argStorage = default; - argStorage._args.Set(0, arg1); - argStorage._args.Set(1, arg2); - argStorage._args.Set(2, arg3); + argStorage._args[0] = arg1; + argStorage._args[1] = arg2; + argStorage._args[2] = arg3; - object? result = _methodBaseInvoker.InvokeDirectWithFewArgs(obj, argStorage._args.AsSpan(_parameterCount)); + object? result = _methodBaseInvoker.InvokeDirectWithFewArgs(obj, ((Span)argStorage._args).Slice(0, 3)); DebugAnnotations.PreviousCallContainsDebuggerStepInCode(); return result; } @@ -116,12 +116,12 @@ public static MethodInvoker Create(MethodBase method) } StackAllocatedArguments argStorage = default; - argStorage._args.Set(0, arg1); - argStorage._args.Set(1, arg2); - argStorage._args.Set(2, arg3); - argStorage._args.Set(3, arg4); + argStorage._args[0] = arg1; + argStorage._args[1] = arg2; + argStorage._args[2] = arg3; + argStorage._args[3] = arg4; - object? result = _methodBaseInvoker.InvokeDirectWithFewArgs(obj, argStorage._args.AsSpan(_parameterCount)); + object? result = _methodBaseInvoker.InvokeDirectWithFewArgs(obj, ((Span)argStorage._args).Slice(0, 4)); DebugAnnotations.PreviousCallContainsDebuggerStepInCode(); return result; } diff --git a/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs b/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs index a7d8701061e5a..6dbd4b3495ab0 100644 --- a/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs +++ b/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs @@ -67,27 +67,21 @@ public static object CreateInstance( } // Attempt to use the stack allocated arg values if <= 4 ctor args. - Span values; StackAllocatedObjects stackValues = default; int maxArgs = GetMaxArgCount(); - if (maxArgs <= StackAllocatedObjects.MaxStackAllocArgCount / 2) - { - values = MemoryMarshal.CreateSpan(ref stackValues._args._arg0, maxArgs * 2); - } - else - { - values = new Span(new object?[maxArgs * 2], 0, maxArgs * 2); - } + Span values = maxArgs <= StackAllocatedObjects.MaxStackAllocArgCount / 2 ? + stackValues : + new object?[maxArgs * 2]; Span ctorArgs = values.Slice(0, maxArgs); - Span bestCtorArgs = values.Slice(maxArgs); + Span bestCtorArgs = values.Slice(maxArgs, maxArgs); #else constructors = CreateConstructorInfoExs(instanceType); object?[]? ctorArgs = null; object?[]? bestCtorArgs = null; #endif - ConstructorMatcher matcher = default; + scoped ConstructorMatcher matcher = default; ConstructorInfoEx? constructor; IServiceProviderIsService? serviceProviderIsService = provider.GetService(); // if container supports using IServiceProviderIsService, we try to find the longest ctor that @@ -124,7 +118,7 @@ public static object CreateInstance( } int bestLength = -1; - ConstructorMatcher bestMatcher = default; + scoped ConstructorMatcher bestMatcher = default; bool multipleBestLengthFound = false; // Find the constructor with the most matches. @@ -1223,17 +1217,11 @@ public static void ClearCache(Type[]? _) } } - [StructLayout(LayoutKind.Sequential)] - private ref struct StackAllocatedObjects + [InlineArray(MaxStackAllocArgCount)] + private struct StackAllocatedObjects { internal const int MaxStackAllocArgCount = 8; - internal StackAllocatedObjectValues _args; - - [InlineArray(MaxStackAllocArgCount)] - internal struct StackAllocatedObjectValues - { - internal object? _arg0; - } + private object? _arg0; } #endif diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 0a2eb4515d758..aabc63e9e2e50 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -454,7 +454,6 @@ - @@ -472,6 +471,7 @@ + @@ -615,7 +615,6 @@ - @@ -2766,4 +2765,4 @@ - + \ No newline at end of file diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/StreamWriter.cs b/src/libraries/System.Private.CoreLib/src/System/IO/StreamWriter.cs index 6eaa2c47cae17..d11c1313ba84d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/StreamWriter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/StreamWriter.cs @@ -531,7 +531,7 @@ public override void Write([StringSyntax(StringSyntaxAttribute.CompositeFormat)] if (GetType() == typeof(StreamWriter)) { TwoObjects two = new TwoObjects(arg0, arg1); - WriteFormatHelper(format, MemoryMarshal.CreateReadOnlySpan(ref two.Arg0, 2), appendNewLine: false); + WriteFormatHelper(format, two, appendNewLine: false); } else { @@ -544,7 +544,7 @@ public override void Write([StringSyntax(StringSyntaxAttribute.CompositeFormat)] if (GetType() == typeof(StreamWriter)) { ThreeObjects three = new ThreeObjects(arg0, arg1, arg2); - WriteFormatHelper(format, MemoryMarshal.CreateReadOnlySpan(ref three.Arg0, 3), appendNewLine: false); + WriteFormatHelper(format, three, appendNewLine: false); } else { @@ -585,7 +585,7 @@ public override void WriteLine([StringSyntax(StringSyntaxAttribute.CompositeForm if (GetType() == typeof(StreamWriter)) { TwoObjects two = new TwoObjects(arg0, arg1); - WriteFormatHelper(format, MemoryMarshal.CreateReadOnlySpan(ref two.Arg0, 2), appendNewLine: true); + WriteFormatHelper(format, two, appendNewLine: true); } else { @@ -598,7 +598,7 @@ public override void WriteLine([StringSyntax(StringSyntaxAttribute.CompositeForm if (GetType() == typeof(StreamWriter)) { ThreeObjects three = new ThreeObjects(arg0, arg1, arg2); - WriteFormatHelper(format, MemoryMarshal.CreateReadOnlySpan(ref three.Arg0, 3), appendNewLine: true); + WriteFormatHelper(format, three, appendNewLine: true); } else { diff --git a/src/libraries/System.Private.CoreLib/src/System/ParamsArray.cs b/src/libraries/System.Private.CoreLib/src/System/InlineArrays.cs similarity index 63% rename from src/libraries/System.Private.CoreLib/src/System/ParamsArray.cs rename to src/libraries/System.Private.CoreLib/src/System/InlineArrays.cs index b1dde8c030138..78394062ec942 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ParamsArray.cs +++ b/src/libraries/System.Private.CoreLib/src/System/InlineArrays.cs @@ -1,13 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// These types are temporary workarounds for an inability to stackalloc object references. -// Once we're able to do `stackalloc object[n]`, these can be removed. - -// Suppress warnings for unused private fields -#pragma warning disable CS0169, CA1823, IDE0051, IDE0044 - -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace System @@ -15,7 +8,7 @@ namespace System [InlineArray(2)] internal struct TwoObjects { - internal object? Arg0; + private object? _arg0; public TwoObjects(object? arg0, object? arg1) { @@ -27,7 +20,7 @@ public TwoObjects(object? arg0, object? arg1) [InlineArray(3)] internal struct ThreeObjects { - internal object? Arg0; + private object? _arg0; public ThreeObjects(object? arg0, object? arg1, object? arg2) { @@ -36,4 +29,10 @@ public ThreeObjects(object? arg0, object? arg1, object? arg2) this[2] = arg2; } } + + [InlineArray(8)] + internal struct EightObjects + { + private object? _ref0; + } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs index 2be8185c4ca68..9778b00d1080d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs @@ -245,8 +245,8 @@ internal object InvokeWithFewArgs(Span arguments) Debug.Assert(_argCount <= MaxStackAllocArgCount); StackAllocatedArgumentsWithCopyBack stackArgStorage = default; - Span copyOfArgs = stackArgStorage._args.AsSpan(_argCount); - scoped Span shouldCopyBack = stackArgStorage._shouldCopyBack.AsSpan(_argCount); + Span copyOfArgs = ((Span)stackArgStorage._args).Slice(0, _argCount); + scoped Span shouldCopyBack = ((Span)stackArgStorage._shouldCopyBack).Slice(0, _argCount); for (int i = 0; i < _argCount; i++) { @@ -279,7 +279,7 @@ internal object InvokeWithFewArgs(Span arguments) internal object InvokeDirectByRef(object? arg1 = null, object? arg2 = null, object? arg3 = null, object? arg4 = null) { StackAllocatedArguments stackStorage = new(arg1, arg2, arg3, arg4); - return InvokeDirectByRefWithFewArgs(stackStorage._args.AsSpan(_argCount)); + return InvokeDirectByRefWithFewArgs(((Span)stackStorage._args).Slice(0, _argCount)); } internal unsafe object InvokeDirectByRefWithFewArgs(Span copyOfArgs) diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs index 087f9953a3af4..72be9d4897d58 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs @@ -190,19 +190,6 @@ internal enum InvokerArgFlags : int internal struct ArgumentData { private T _arg0; - - [UnscopedRef] - public Span AsSpan(int length) - { - Debug.Assert((uint)length <= MaxStackAllocArgCount); - return new Span(ref _arg0, length); - } - - public void Set(int index, T value) - { - Debug.Assert((uint)index < MaxStackAllocArgCount); - Unsafe.Add(ref _arg0, index) = value; - } } // Helper struct to avoid intermediate object[] allocation in calls to the native reflection stack. @@ -214,10 +201,10 @@ internal ref struct StackAllocatedArguments { public StackAllocatedArguments(object? obj1, object? obj2, object? obj3, object? obj4) { - _args.Set(0, obj1); - _args.Set(1, obj2); - _args.Set(2, obj3); - _args.Set(3, obj4); + _args[0] = obj1; + _args[1] = obj2; + _args[2] = obj3; + _args[3] = obj4; } internal ArgumentData _args; diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs index 12d8c62b07258..531a8ed9f8167 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs @@ -118,8 +118,8 @@ internal static void ThrowTargetParameterCountException() Debug.Assert(_argCount <= MaxStackAllocArgCount); StackAllocatedArgumentsWithCopyBack stackArgStorage = default; - Span copyOfArgs = stackArgStorage._args.AsSpan(_argCount); - Span shouldCopyBack = stackArgStorage._shouldCopyBack.AsSpan(_argCount); + Span copyOfArgs = ((Span)stackArgStorage._args).Slice(0, _argCount); + Span shouldCopyBack = ((Span)stackArgStorage._shouldCopyBack).Slice(0, _argCount); object? ret; if ((_strategy & InvokerStrategy.StrategyDetermined_ObjSpanArgs) == 0) diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs index 68380efb9098d..5b4b9048b23f2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs @@ -298,8 +298,8 @@ private void ThrowForBadInvocationFlags() Debug.Assert(_argCount <= MaxStackAllocArgCount); StackAllocatedArgumentsWithCopyBack stackArgStorage = default; - Span copyOfArgs = stackArgStorage._args.AsSpan(_argCount); - scoped Span shouldCopyBack = stackArgStorage._shouldCopyBack.AsSpan(_argCount); + Span copyOfArgs = ((Span)stackArgStorage._args).Slice(0, _argCount); + scoped Span shouldCopyBack = ((Span)stackArgStorage._shouldCopyBack).Slice(0, _argCount); for (int i = 0; i < _argCount; i++) { @@ -332,7 +332,7 @@ private void ThrowForBadInvocationFlags() internal object? InvokeDirectByRef(object? obj, object? arg1 = null, object? arg2 = null, object? arg3 = null, object? arg4 = null) { StackAllocatedArguments stackStorage = new(arg1, arg2, arg3, arg4); - return InvokeDirectByRefWithFewArgs(obj, stackStorage._args.AsSpan(_argCount)); + return InvokeDirectByRefWithFewArgs(obj, ((Span)stackStorage._args).Slice(0, _argCount)); } internal unsafe object? InvokeDirectByRefWithFewArgs(object? obj, Span copyOfArgs) diff --git a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/AsciiStringSearchValuesTeddyBase.cs b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/AsciiStringSearchValuesTeddyBase.cs index e465aae605fb1..df6c8a90ac47f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/AsciiStringSearchValuesTeddyBase.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/AsciiStringSearchValuesTeddyBase.cs @@ -109,7 +109,7 @@ internal abstract class AsciiStringSearchValuesTeddyBase _n0Low, _n0High, @@ -121,9 +121,7 @@ protected AsciiStringSearchValuesTeddyBase(ReadOnlySpan values, HashSet< Debug.Assert(!TBucketized.Value); Debug.Assert(n is 2 or 3); - _buckets = new EightPackedReferences(MemoryMarshal.CreateReadOnlySpan( - ref Unsafe.As(ref MemoryMarshal.GetReference(values)), - values.Length)); + ReadOnlySpan.CastUp(values).CopyTo(_buckets); (_n0Low, _n0High) = TeddyBucketizer.GenerateNonBucketizedFingerprint(values, offset: 0); (_n1Low, _n1High) = TeddyBucketizer.GenerateNonBucketizedFingerprint(values, offset: 1); @@ -139,7 +137,7 @@ protected AsciiStringSearchValuesTeddyBase(string[][] buckets, ReadOnlySpan)buckets).CopyTo(_buckets); (_n0Low, _n0High) = TeddyBucketizer.GenerateBucketizedFingerprint(buckets, offset: 0); (_n1Low, _n1High) = TeddyBucketizer.GenerateBucketizedFingerprint(buckets, offset: 1); diff --git a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/Helpers/EightPackedReferences.cs b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/Helpers/EightPackedReferences.cs deleted file mode 100644 index b85a7e145c51a..0000000000000 --- a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/Helpers/EightPackedReferences.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace System.Buffers -{ - [InlineArray(8)] - internal struct EightPackedReferences - { -#pragma warning disable CA1823 // Unused field -- https://github.com/dotnet/roslyn-analyzers/issues/6788 - private object? _ref0; -#pragma warning restore CA1823 - - public EightPackedReferences(ReadOnlySpan values) - { - Debug.Assert(values.Length is > 0 and <= 8, $"Got {values.Length} values"); - - values.CopyTo(this!); - } - } -} diff --git a/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs b/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs index d568696836d76..7f4f642526d45 100644 --- a/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs +++ b/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs @@ -427,13 +427,13 @@ public static string Format([StringSyntax(StringSyntaxAttribute.CompositeFormat) public static string Format([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0, object? arg1) { TwoObjects two = new TwoObjects(arg0, arg1); - return FormatHelper(null, format, MemoryMarshal.CreateReadOnlySpan(ref two.Arg0, 2)); + return FormatHelper(null, format, two); } public static string Format([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0, object? arg1, object? arg2) { ThreeObjects three = new ThreeObjects(arg0, arg1, arg2); - return FormatHelper(null, format, MemoryMarshal.CreateReadOnlySpan(ref three.Arg0, 3)); + return FormatHelper(null, format, three); } public static string Format([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, params object?[] args) @@ -456,13 +456,13 @@ public static string Format(IFormatProvider? provider, [StringSyntax(StringSynta public static string Format(IFormatProvider? provider, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0, object? arg1) { TwoObjects two = new TwoObjects(arg0, arg1); - return FormatHelper(provider, format, MemoryMarshal.CreateReadOnlySpan(ref two.Arg0, 2)); + return FormatHelper(provider, format, two); } public static string Format(IFormatProvider? provider, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0, object? arg1, object? arg2) { ThreeObjects three = new ThreeObjects(arg0, arg1, arg2); - return FormatHelper(provider, format, MemoryMarshal.CreateReadOnlySpan(ref three.Arg0, 3)); + return FormatHelper(provider, format, three); } public static string Format(IFormatProvider? provider, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, params object?[] args) diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs b/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs index c1f86a1ca2d1e..6f7b0abfa9b91 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs @@ -1366,13 +1366,13 @@ public StringBuilder AppendFormat([StringSyntax(StringSyntaxAttribute.CompositeF public StringBuilder AppendFormat([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0, object? arg1) { TwoObjects two = new TwoObjects(arg0, arg1); - return AppendFormatHelper(null, format, MemoryMarshal.CreateReadOnlySpan(ref two.Arg0, 2)); + return AppendFormatHelper(null, format, two); } public StringBuilder AppendFormat([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0, object? arg1, object? arg2) { ThreeObjects three = new ThreeObjects(arg0, arg1, arg2); - return AppendFormatHelper(null, format, MemoryMarshal.CreateReadOnlySpan(ref three.Arg0, 3)); + return AppendFormatHelper(null, format, three); } public StringBuilder AppendFormat([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, params object?[] args) @@ -1395,13 +1395,13 @@ public StringBuilder AppendFormat(IFormatProvider? provider, [StringSyntax(Strin public StringBuilder AppendFormat(IFormatProvider? provider, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0, object? arg1) { TwoObjects two = new TwoObjects(arg0, arg1); - return AppendFormatHelper(provider, format, MemoryMarshal.CreateReadOnlySpan(ref two.Arg0, 2)); + return AppendFormatHelper(provider, format, two); } public StringBuilder AppendFormat(IFormatProvider? provider, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0, object? arg1, object? arg2) { ThreeObjects three = new ThreeObjects(arg0, arg1, arg2); - return AppendFormatHelper(provider, format, MemoryMarshal.CreateReadOnlySpan(ref three.Arg0, 3)); + return AppendFormatHelper(provider, format, three); } public StringBuilder AppendFormat(IFormatProvider? provider, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, params object?[] args)