Skip to content

Commit 3961b78

Browse files
committed
Optimize step4 to skip re-layout if width matches
1 parent f9f3d31 commit 3961b78

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

packages/core/lib/src/widgets/html_table.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ class _TableRenderLayouter {
397397
(availableWidth == null || columnWidths.sum <= availableWidth)) {
398398
return _TableDataStep3(
399399
step2,
400+
cellSizes: cellSizes,
400401
columnWidths: columnWidths,
401402
);
402403
}
@@ -458,6 +459,7 @@ class _TableRenderLayouter {
458459

459460
return _TableDataStep3(
460461
step2,
462+
cellSizes: cellSizes,
461463
columnWidths: columnWidths,
462464
);
463465
}
@@ -504,22 +506,27 @@ class _TableRenderLayouter {
504506
final step2 = step3.step2;
505507
final step1 = step2.step1;
506508
final cells = step1.cells;
509+
final cellSizes = step3.cellSizes;
507510
final children = step1.children;
508511

509512
final childSizes = List.filled(children.length, Size.zero);
510513
final rowHeights = List.filled(step1.rowCount, .0);
511514

512515
for (var i = 0; i < children.length; i++) {
516+
final cellSize = cellSizes[i];
513517
final child = children[i];
514518
final data = cells[i];
515519

516-
// always re-layout because we cannot be sure whether
517-
// children will render the same inside an unconstrained and a tight box
518520
final childWidth = data.calculateWidth(tro, step3.columnWidths);
519-
final cc1 = BoxConstraints.tightFor(width: childWidth);
520-
final childSize = layouter(child, cc1);
521-
logger.fine('[4] Got child#$i $childSize@$cc1');
522-
childSizes[i] = childSize;
521+
Size childSize;
522+
if (cellSize != null && cellSize.width == childWidth) {
523+
childSize = cellSize;
524+
} else {
525+
final cc1 = BoxConstraints.tightFor(width: childWidth);
526+
childSize = layouter(child, cc1);
527+
logger.fine('[4] Got child#$i $childSize@$cc1');
528+
childSizes[i] = childSize;
529+
}
523530

524531
// distribute cell height across spanned rows
525532
final rowHeight =
@@ -692,10 +699,12 @@ class _TableDataStep2 {
692699
class _TableDataStep3 {
693700
final _TableDataStep2 step2;
694701

702+
final List<Size?> cellSizes;
695703
final List<double> columnWidths;
696704

697705
const _TableDataStep3(
698706
this.step2, {
707+
required this.cellSizes,
699708
required this.columnWidths,
700709
});
701710
}

0 commit comments

Comments
 (0)