Cache Entries' Count for loops (#23707)

Cache the value of Entries.Count into a local when enumerating loops, rather than re-evaluating on each pass.
This commit is contained in:
Martin Costello 2020-07-08 17:40:49 +01:00 committed by GitHub
parent 74c5dde694
commit 769fc6d289
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -111,7 +111,8 @@ namespace Microsoft.AspNetCore.Html
throw new ArgumentNullException(nameof(destination));
}
for (var i = 0; i < Entries.Count; i++)
var count = Entries.Count;
for (var i = 0; i < count; i++)
{
var entry = Entries[i];
@ -140,7 +141,8 @@ namespace Microsoft.AspNetCore.Html
throw new ArgumentNullException(nameof(destination));
}
for (var i = 0; i < Entries.Count; i++)
var count = Entries.Count;
for (var i = 0; i < count; i++)
{
var entry = Entries[i];
@ -176,7 +178,8 @@ namespace Microsoft.AspNetCore.Html
throw new ArgumentNullException(nameof(encoder));
}
for (var i = 0; i < Entries.Count; i++)
var count = Entries.Count;
for (var i = 0; i < count; i++)
{
var entry = Entries[i];