Skip to content

Commit 2d22951

Browse files
authored
Cache Array.Empty<object>() in RequestDelegateFactory (#41816)
1 parent 77042af commit 2d22951

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Http/Http.Extensions/src/RequestDelegateFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static partial class RequestDelegateFactory
5656
private static readonly MethodInfo ValueTaskOfTToValueTaskOfObjectMethod = typeof(RequestDelegateFactory).GetMethod(nameof(ValueTaskOfTToValueTaskOfObject), BindingFlags.NonPublic | BindingFlags.Static)!;
5757
private static readonly MethodInfo PopulateMetadataForParameterMethod = typeof(RequestDelegateFactory).GetMethod(nameof(PopulateMetadataForParameter), BindingFlags.NonPublic | BindingFlags.Static)!;
5858
private static readonly MethodInfo PopulateMetadataForEndpointMethod = typeof(RequestDelegateFactory).GetMethod(nameof(PopulateMetadataForEndpoint), BindingFlags.NonPublic | BindingFlags.Static)!;
59-
private static readonly MethodInfo ArrayEmptyMethod = typeof(Array).GetMethod(nameof(Array.Empty), BindingFlags.Public | BindingFlags.Static)!;
59+
private static readonly MethodInfo ArrayEmptyOfObjectMethod = typeof(Array).GetMethod(nameof(Array.Empty), BindingFlags.Public | BindingFlags.Static)!.MakeGenericMethod(new Type[] { typeof(object) });
6060

6161
// Call WriteAsJsonAsync<object?>() to serialize the runtime return type rather than the declared return type.
6262
// https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-polymorphism
@@ -391,7 +391,7 @@ private static Expression CreateRouteHandlerInvocationContextBase(FactoryContext
391391
// non-generic implementation of RouteHandlerInvocationContext.
392392
Expression paramArray = factoryContext.BoxedArgs.Length > 0
393393
? Expression.NewArrayInit(typeof(object), factoryContext.BoxedArgs)
394-
: Expression.Call(ArrayEmptyMethod.MakeGenericMethod(new Type[] { typeof(object) }));
394+
: Expression.Call(ArrayEmptyOfObjectMethod);
395395
var fallbackConstruction = Expression.New(
396396
DefaultRouteHandlerInvocationContextConstructor,
397397
new Expression[] { HttpContextExpr, paramArray });

0 commit comments

Comments
 (0)