Skip to content
Prev Previous commit
Next Next commit
libraries/
Add special case for array construction during Invoke.
  • Loading branch information
AaronRobinsonMSFT committed Nov 9, 2021
commit b5bdbfad0aac44a1b92ac7f1151728ef01303ac4
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,25 @@ public override object Invoke(BindingFlags invokeAttr, Binder? binder, object?[]
throw new TargetParameterCountException(SR.Arg_ParmCnt);
}

// Array construction is a special case.
if (DeclaringType is not null && DeclaringType.IsArray)
{
Span<int> args = stackalloc int[actualCount];
for (int i = 0; i < actualCount; ++i)
{
args[i] = (int)parameters![i]!;
}
return InvokeArrayCtorWorker(in args);
}

StackAllocedArguments stackArgs = default;
Span<object?> arguments = default;
if (actualCount != 0)
{
arguments = CheckArguments(ref stackArgs, parameters, binder, invokeAttr, culture, ArgumentTypes);
}

object retValue = InvokeCtorWorker(invokeAttr, arguments);
object retValue = InvokeCtorWorker(invokeAttr, in arguments);

// copy out. This should be made only if ByRef are present.
// n.b. cannot use Span<T>.CopyTo, as parameters.GetType() might not actually be typeof(object[])
Expand Down