Fix: performance regression of the Table element #320

This commit is contained in:
MarcinZiabek
2022-10-11 23:19:13 +02:00
parent 6801425082
commit e1f7cff4aa
+6 -3
View File
@@ -24,6 +24,7 @@ namespace QuestPDF.Elements.Table
// inner table: list of all cells that ends at the corresponding row
private TableCell[][] CellsCache { get; set; }
private int MaxRow { get; set; }
private int MaxRowSpan { get; set; }
internal override void Initialize(IPageContext pageContext, ICanvas canvas)
{
@@ -56,6 +57,7 @@ namespace QuestPDF.Elements.Table
if (Cells.Count == 0)
{
MaxRow = 0;
MaxRowSpan = 1;
CellsCache = Array.Empty<TableCell[]>();
return;
@@ -66,6 +68,7 @@ namespace QuestPDF.Elements.Table
.ToDictionary(x => x.Key, x => x.OrderBy(x => x.Column).ToArray());
MaxRow = groups.Max(x => x.Key);
MaxRowSpan = Cells.Max(x => x.RowSpan);
CellsCache = Enumerable
.Range(0, MaxRow + 1)
@@ -199,10 +202,10 @@ namespace QuestPDF.Elements.Table
currentRow = cell.Row;
}
// cell visibility optimizations
if (cell.Row > maxRenderingRow)
continue;
if (cell.Row > maxRenderingRow + MaxRowSpan)
break;
// calculate cell position / size
var topOffset = rowBottomOffsets[cell.Row - 1];