Skip to content

Commit 77cb103

Browse files
committed
Don't allocate empty IInvocation.Arguments arrays
1 parent a92fe78 commit 77cb103

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/Castle.Core/DynamicProxy/Generators/MethodWithInvocationGenerator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ public void CopyIn(out LocalReference argumentsArray, out bool hasByRefArguments
266266
method.CodeBuilder.AddStatement(
267267
new AssignStatement(
268268
argumentsArray,
269-
new NewArrayExpression(arguments.Length, typeof(object))));
269+
arguments.Length > 0 ? new NewArrayExpression(arguments.Length, typeof(object))
270+
: new MethodInvocationExpression(instance: null, ArrayMethods.EmptyOfObject)));
270271

271272
for (int i = 0, n = arguments.Length; i < n; ++i)
272273
{
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2004-2026 Castle Project - http://www.castleproject.org/
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace Castle.DynamicProxy.Tokens
16+
{
17+
using System;
18+
using System.Reflection;
19+
20+
internal static class ArrayMethods
21+
{
22+
public static readonly MethodInfo EmptyOfObject = typeof(Array).GetMethod(nameof(Array.Empty)).MakeGenericMethod(typeof(object));
23+
}
24+
}

0 commit comments

Comments
 (0)