ソースを参照

Fix: performance regression of the Table element #320

MarcinZiabek 3 年 前
コミット
e1f7cff4aa
1 ファイル変更6 行追加3 行削除
  1. 6 3
      QuestPDF/Elements/Table/Table.cs

+ 6 - 3
QuestPDF/Elements/Table/Table.cs

@@ -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];