diff --git a/layout/generic/nsGridContainerFrame.cpp b/layout/generic/nsGridContainerFrame.cpp index f6f23b598cf1..d172cc939b2f 100644 --- a/layout/generic/nsGridContainerFrame.cpp +++ b/layout/generic/nsGridContainerFrame.cpp @@ -1534,15 +1534,12 @@ nsGridContainerFrame::FindAutoCol(uint32_t aStartCol, uint32_t aLockedRow, // Find the first gap in the current row that's at least 'extent' wide. // ('gap' tracks how wide the current column gap is.) for (uint32_t j = candidate, gap = 0; j < len && gap < extent; ++j) { - ++gap; // tentative, but we may reset it below if a column is occupied - if (cellsInRow[j].mIsOccupied) { - // Optimization: skip as many occupied cells as we can. - do { - ++j; - } while (j < len && cellsInRow[j].mIsOccupied); - candidate = j; - gap = 0; + if (!cellsInRow[j].mIsOccupied) { + ++gap; + continue; } + candidate = j + 1; + gap = 0; } if (lastCandidate < candidate && i != iStart) { // Couldn't fit 'extent' tracks at 'lastCandidate' here so we must