Skip to content

Commit abc2335

Browse files
authored
Avoid allocations from LINQ.Reverse() (#28389)
1 parent 1a8f5a8 commit abc2335

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Http/Http/src/Builder/ApplicationBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class ApplicationBuilder : IApplicationBuilder
1616
private const string ServerFeaturesKey = "server.Features";
1717
private const string ApplicationServicesKey = "application.Services";
1818

19-
private readonly IList<Func<RequestDelegate, RequestDelegate>> _components = new List<Func<RequestDelegate, RequestDelegate>>();
19+
private readonly List<Func<RequestDelegate, RequestDelegate>> _components = new List<Func<RequestDelegate, RequestDelegate>>();
2020

2121
public ApplicationBuilder(IServiceProvider serviceProvider)
2222
{
@@ -99,9 +99,9 @@ public RequestDelegate Build()
9999
return Task.CompletedTask;
100100
};
101101

102-
foreach (var component in _components.Reverse())
102+
for (var c = _components.Count - 1; c >= 0; c--)
103103
{
104-
app = component(app);
104+
app = _components[c](app);
105105
}
106106

107107
return app;

0 commit comments

Comments
 (0)