sc/source/ui/view/tabview2.cxx |   24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

New commits:
commit d20598d14a95675a436736679ab4a82a8cc3a703
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Mon Feb 7 20:17:42 2022 +0100
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Tue Feb 8 12:27:54 2022 +0100

    optimize ScTabView::SkipCursorVertical() for many hidden rows
    
    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 <l.lu...@collabora.com>

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<SCROW>(nLastHiddenRow + 1, 
rDoc.MaxRow());
+                    else
+                        ++rCurY;
                 else
-                    --rCurY;
+                    if (nFirstHiddenRow >= 0)
+                        rCurY = std::max<SCROW>(nFirstHiddenRow - 1, 0);
+                    else
+                        --rCurY;
+            }
         }
     }
     while (bSkipCell);

Reply via email to