From d20598d14a95675a436736679ab4a82a8cc3a703 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Mon, 7 Feb 2022 20:17:42 +0100 Subject: optimize ScTabView::SkipCursorVertical() for many hidden rows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code skips all hidden rows, and it does so one by one, until it encounters the last row, and then it reverses and goes back. With a huge sheet it may spend a noticeable time doing this. Since the RowHidden() function gives a range, use that to skip hidden rows faster. Change-Id: I14a990d288d28e9cab69d7dcc7f0dc9210434859 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129643 Tested-by: Jenkins Reviewed-by: Luboš Luňák --- sc/source/ui/view/tabview2.cxx | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'sc') diff --git a/sc/source/ui/view/tabview2.cxx b/sc/source/ui/view/tabview2.cxx index bf2f1603815b..b5ca9b40d521 100644 --- a/sc/source/ui/view/tabview2.cxx +++ b/sc/source/ui/view/tabview2.cxx @@ -840,8 +840,14 @@ void ScTabView::SkipCursorVertical(SCCOL& rCurX, SCROW& rCurY, SCROW nOldY, SCRO bool bVFlip = false; do { - SCROW nLastRow = -1; - bSkipCell = rDoc.RowHidden(rCurY, nTab, nullptr, &nLastRow) || rDoc.IsVerOverlapped( rCurX, rCurY, nTab ); + SCROW nFirstHiddenRow = -1; + SCROW nLastHiddenRow = -1; + bSkipCell = rDoc.RowHidden(rCurY, nTab, &nFirstHiddenRow, &nLastHiddenRow); + if (!bSkipCell) + { + nFirstHiddenRow = nLastHiddenRow = -1; + bSkipCell = rDoc.IsVerOverlapped( rCurX, rCurY, nTab ); + } if (bSkipProtected && !bSkipCell) bSkipCell = rDoc.HasAttrib(rCurX, rCurY, nTab, rCurX, rCurY, nTab, HasAttrFlags::Protected); if (bSkipUnprotected && !bSkipCell) @@ -867,10 +873,20 @@ void ScTabView::SkipCursorVertical(SCCOL& rCurX, SCROW& rCurY, SCROW nOldY, SCRO } } else + { + // nFirstRow/nLastRow are set only if the row is hidden, in which case we always skip, + // so as an optimization skip to the first row after the hidden range if (nMovY > 0) - ++rCurY; + if (nLastHiddenRow >= 0) + rCurY = std::min(nLastHiddenRow + 1, rDoc.MaxRow()); + else + ++rCurY; else - --rCurY; + if (nFirstHiddenRow >= 0) + rCurY = std::max(nFirstHiddenRow - 1, 0); + else + --rCurY; + } } } while (bSkipCell); -- cgit