From d4098037a4a6bee464fde4b70644e730e13b487f Mon Sep 17 00:00:00 2001 From: win7-7 Date: Sun, 16 Feb 2020 16:06:53 +0200 Subject: Issue #1355 - Make nsTableCellFrame::GetColIndex/GetRowIndex faster We can devirtualize it, remove some branches. --- layout/tables/nsTableRowFrame.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'layout/tables/nsTableRowFrame.cpp') diff --git a/layout/tables/nsTableRowFrame.cpp b/layout/tables/nsTableRowFrame.cpp index 8bbaf50f5f..02b85a141f 100644 --- a/layout/tables/nsTableRowFrame.cpp +++ b/layout/tables/nsTableRowFrame.cpp @@ -235,7 +235,7 @@ nsTableRowFrame::InsertFrames(ChildListID aListID, // insert the cells into the cell map int32_t colIndex = -1; if (prevCellFrame) { - prevCellFrame->GetColIndex(colIndex); + colIndex = prevCellFrame->ColIndex(); } tableFrame->InsertCells(cellChildren, GetRowIndex(), colIndex); @@ -647,8 +647,7 @@ CalcAvailISize(nsTableFrame& aTableFrame, nsTableCellFrame& aCellFrame) { nscoord cellAvailISize = 0; - int32_t colIndex; - aCellFrame.GetColIndex(colIndex); + uint32_t colIndex = aCellFrame.ColIndex(); int32_t colspan = aTableFrame.GetEffectiveColSpan(aCellFrame); NS_ASSERTION(colspan > 0, "effective colspan should be positive"); nsTableFrame* fifTable = @@ -787,12 +786,12 @@ nsTableRowFrame::ReflowChildren(nsPresContext* aPresContext, } } - int32_t cellColIndex; - cellFrame->GetColIndex(cellColIndex); + uint32_t cellColIndex = cellFrame->ColIndex(); cellColSpan = aTableFrame.GetEffectiveColSpan(*cellFrame); // If the adjacent cell is in a prior row (because of a rowspan) add in the space - if (prevColIndex != (cellColIndex - 1)) { + // NOTE: prevColIndex can be -1 here. + if (prevColIndex != (static_cast(cellColIndex) - 1)) { iCoord += GetSpaceBetween(prevColIndex, cellColIndex, cellColSpan, aTableFrame, false); } @@ -1160,8 +1159,7 @@ nsTableRowFrame::CollapseRowIfNecessary(nscoord aRowOffset, shift = rowRect.BSize(wm); nsTableCellFrame* cellFrame = GetFirstCell(); if (cellFrame) { - int32_t rowIndex; - cellFrame->GetRowIndex(rowIndex); + uint32_t rowIndex = cellFrame->RowIndex(); shift += tableFrame->GetRowSpacing(rowIndex); while (cellFrame) { LogicalRect cRect = cellFrame->GetLogicalRect(wm, containerSize); @@ -1192,13 +1190,13 @@ nsTableRowFrame::CollapseRowIfNecessary(nscoord aRowOffset, for (nsIFrame* kidFrame : mFrames) { nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame); if (cellFrame) { - int32_t cellColIndex; - cellFrame->GetColIndex(cellColIndex); + uint32_t cellColIndex = cellFrame->ColIndex(); int32_t cellColSpan = tableFrame->GetEffectiveColSpan(*cellFrame); // If the adjacent cell is in a prior row (because of a rowspan) add in // the space - if (prevColIndex != (cellColIndex - 1)) { + // NOTE: prevColIndex can be -1 here. + if (prevColIndex != (static_cast(cellColIndex) - 1)) { iPos += GetSpaceBetween(prevColIndex, cellColIndex, cellColSpan, *tableFrame, true); } @@ -1311,9 +1309,9 @@ nsTableRowFrame::InsertCellFrame(nsTableCellFrame* aFrame, for (nsIFrame* child : mFrames) { nsTableCellFrame *cellFrame = do_QueryFrame(child); if (cellFrame) { - int32_t colIndex; - cellFrame->GetColIndex(colIndex); - if (colIndex < aColIndex) { + uint32_t colIndex = cellFrame->ColIndex(); + // Can aColIndex be -1 here? Let's assume it can for now. + if (static_cast(colIndex) < aColIndex) { priorCell = cellFrame; } else break; -- cgit v1.2.3