Skip to content

Commit 769fc6d

Browse files
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.
1 parent 74c5dde commit 769fc6d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Html/Abstractions/src/HtmlContentBuilder.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ public void CopyTo(IHtmlContentBuilder destination)
111111
throw new ArgumentNullException(nameof(destination));
112112
}
113113

114-
for (var i = 0; i < Entries.Count; i++)
114+
var count = Entries.Count;
115+
for (var i = 0; i < count; i++)
115116
{
116117
var entry = Entries[i];
117118

@@ -140,7 +141,8 @@ public void MoveTo(IHtmlContentBuilder destination)
140141
throw new ArgumentNullException(nameof(destination));
141142
}
142143

143-
for (var i = 0; i < Entries.Count; i++)
144+
var count = Entries.Count;
145+
for (var i = 0; i < count; i++)
144146
{
145147
var entry = Entries[i];
146148

@@ -176,7 +178,8 @@ public void WriteTo(TextWriter writer, HtmlEncoder encoder)
176178
throw new ArgumentNullException(nameof(encoder));
177179
}
178180

179-
for (var i = 0; i < Entries.Count; i++)
181+
var count = Entries.Count;
182+
for (var i = 0; i < count; i++)
180183
{
181184
var entry = Entries[i];
182185

0 commit comments

Comments
 (0)