Reduce creation of new arrays in Queue<T>

This commit is contained in:
Maarten Balliauw
2022-05-10 13:31:42 +02:00
parent b7bc640e31
commit fae2205ff8
2 changed files with 17 additions and 2 deletions
+3 -1
View File
@@ -42,7 +42,9 @@ namespace QuestPDF.Elements.Table
public void ResetState()
{
Cells.ForEach(x => x.IsRendered = false);
foreach (var x in Cells)
x.IsRendered = false;
CurrentRow = 1;
}
+14 -1
View File
@@ -20,7 +20,20 @@ namespace QuestPDF.Elements.Text
public void ResetState()
{
RenderingQueue = new Queue<ITextBlockItem>(Items);
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
// Create queue when we don't have one yet, otherwise clear the existing one so it re-uses the internal array under the hood.
if (RenderingQueue == null)
{
RenderingQueue = new Queue<ITextBlockItem>(Items);
}
else
{
RenderingQueue.Clear();
foreach (var item in Items)
RenderingQueue.Enqueue(item);
}
CurrentElementIndex = 0;
}