Browse Source

Avoid allocations from LINQ.Reverse() (#28389)

Paulo Morgado 5 years ago
parent
commit
abc2335a3a
1 changed files with 3 additions and 3 deletions
  1. 3 3
      src/Http/Http/src/Builder/ApplicationBuilder.cs

+ 3 - 3
src/Http/Http/src/Builder/ApplicationBuilder.cs

@@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Builder
         private const string ServerFeaturesKey = "server.Features";
         private const string ApplicationServicesKey = "application.Services";
 
-        private readonly IList<Func<RequestDelegate, RequestDelegate>> _components = new List<Func<RequestDelegate, RequestDelegate>>();
+        private readonly List<Func<RequestDelegate, RequestDelegate>> _components = new List<Func<RequestDelegate, RequestDelegate>>();
 
         public ApplicationBuilder(IServiceProvider serviceProvider)
         {
@@ -99,9 +99,9 @@ namespace Microsoft.AspNetCore.Builder
                 return Task.CompletedTask;
             };
 
-            foreach (var component in _components.Reverse())
+            for (var c = _components.Count - 1; c >= 0; c--)
             {
-                app = component(app);
+                app = _components[c](app);
             }
 
             return app;