Reduce creation of new arrays in Queue<T>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user