Skip to content

Commit 749a16f

Browse files
committed
Cache collapsed vertical border calculation result
DEVSIX-8836
1 parent 82c8d0b commit 749a16f

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

layout/src/main/java/com/itextpdf/layout/renderer/CollapsedTableBorders.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ This file is part of the iText (R) project.
3232
import java.util.ArrayList;
3333
import java.util.Collections;
3434
import java.util.Comparator;
35+
import java.util.HashMap;
3536
import java.util.List;
37+
import java.util.Map;
3638

3739
class CollapsedTableBorders extends TableBorders {
3840
/**
@@ -57,13 +59,17 @@ class CollapsedTableBorders extends TableBorders {
5759

5860
private static Comparator<Border> borderComparator = new BorderComparator();
5961

62+
private final Map<Integer, List<Border>> verticalBorderComputationResult;
63+
6064
// region constructors
6165
public CollapsedTableBorders(List<CellRenderer[]> rows, int numberOfColumns, Border[] tableBoundingBorders) {
6266
super(rows, numberOfColumns, tableBoundingBorders);
67+
verticalBorderComputationResult = new HashMap<>();
6368
}
6469

6570
public CollapsedTableBorders(List<CellRenderer[]> rows, int numberOfColumns, Border[] tableBoundingBorders, int largeTableIndexOffset) {
6671
super(rows, numberOfColumns, tableBoundingBorders, largeTableIndexOffset);
72+
verticalBorderComputationResult = new HashMap<>();
6773
}
6874
// endregion
6975

@@ -133,16 +139,21 @@ public List<Border> getVerticalBordersCrossingTopHorizontalBorder() {
133139
return borders;
134140
}
135141

142+
136143
@Override
137144
public List<Border> getVerticalBorder(int index) {
138-
if (index == 0) {
139-
List<Border> borderList = TableBorderUtil
140-
.createAndFillBorderList(null, tableBoundingBorders[3], verticalBorders.get(0).size());
141-
return getCollapsedList(verticalBorders.get(0), borderList);
142-
} else if (index == numberOfColumns) {
143-
List<Border> borderList = TableBorderUtil.createAndFillBorderList(null, tableBoundingBorders[1],
144-
verticalBorders.get(verticalBorders.size() - 1).size());
145-
return getCollapsedList(verticalBorders.get(verticalBorders.size() - 1), borderList);
145+
if (index == 0 || index == numberOfColumns) {
146+
if (verticalBorderComputationResult.containsKey(index)) {
147+
return verticalBorderComputationResult.get(index);
148+
}
149+
final int tableBoundingBordersIndex = index == 0 ? 3 : 1;
150+
List<Border> borderList = TableBorderUtil.createAndFillBorderList(
151+
null,
152+
tableBoundingBorders[tableBoundingBordersIndex],
153+
verticalBorders.get(index).size());
154+
List<Border> result = getCollapsedList(verticalBorders.get(index), borderList);
155+
verticalBorderComputationResult.put(index, result);
156+
return result;
146157
} else {
147158
return verticalBorders.get(index);
148159
}
@@ -226,7 +237,7 @@ public CollapsedTableBorders setTopBorderCollapseWith(List<Border> topBorderColl
226237
}
227238

228239
public CollapsedTableBorders setBottomBorderCollapseWith(List<Border> bottomBorderCollapseWith,
229-
List<Border> verticalBordersCrossingBottomBorder) {
240+
List<Border> verticalBordersCrossingBottomBorder) {
230241
this.bottomBorderCollapseWith = new ArrayList<Border>();
231242
if (null != bottomBorderCollapseWith) {
232243
this.bottomBorderCollapseWith.addAll(bottomBorderCollapseWith);

0 commit comments

Comments
 (0)