sc/source/core/data/table1.cxx |   25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

New commits:
commit eaef1432bd0799bbed8dcbd6286942ed1d54ad90
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Fri Nov 29 11:40:57 2024 -0500
Commit:     Justin Luth <justin.l...@collabora.com>
CommitDate: Fri Nov 29 21:16:52 2024 +0100

    tdf#163872 ScTable::SetOptimalHeight: use better way to iterate rows
    
    I stumbled across GetNextValue while looking how I could optimize
    GetValue's use of Search. Since this function needs to iterate
    through every single entry, it was relatively expensive to
    "Search" for the beginning row each time, when we know it will be index++.
    
    Change-Id: I1bc7b6b041b7836aebc4cd2bfd9214851804bf31
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177561
    Reviewed-by: Justin Luth <jl...@mail.com>
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Tested-by: Jenkins

diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 7b3c0aea4c1d..cf22133056cf 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -477,20 +477,25 @@ bool ScTable::SetOptimalHeight(
 
     if (!rCxt.isForceAutoSize())
     {
-        // Optimize - exit early if all rows have defined height - super 
expensive GetOptimalHeight
-        bool bAllRowsAreManualHeight = true;
-        for (SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow)
+        // Optimize - exit early if all rows have defined height: super 
expensive GetOptimalHeight
+        size_t nIndex;
+        SCROW nRow;
+        CRFlags nRowFlags = pRowFlags->GetValue(nStartRow, nIndex, nRow); // 
changes nIndex, nRow
+        if (nRowFlags & CRFlags::ManualSize) // first block of rows is manual 
- are all the rest?
         {
-            size_t nDummy;
-            CRFlags nRowFlags = pRowFlags->GetValue(nRow, nDummy, nRow); // 
NOTE: nRow might change
-            if (!(nRowFlags & CRFlags::ManualSize))
+            bool bAllRowsAreManualHeight = true;
+            while (nRow < nEndRow)
             {
-                bAllRowsAreManualHeight = false;
-                break;
+                nRowFlags = pRowFlags->GetNextValue(nIndex, nRow);
+                if (!(nRowFlags & CRFlags::ManualSize))
+                {
+                    bAllRowsAreManualHeight = false;
+                    break;
+                }
             }
+            if (bAllRowsAreManualHeight)
+                return false;
         }
-        if (bAllRowsAreManualHeight)
-            return false;
     }
 
     SCSIZE  nCount = static_cast<SCSIZE>(nEndRow-nStartRow+1);

Reply via email to