From eaef1432bd0799bbed8dcbd6286942ed1d54ad90 Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Fri, 29 Nov 2024 11:40:57 -0500 Subject: [PATCH] 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 Reviewed-by: Noel Grandin Tested-by: Jenkins --- sc/source/core/data/table1.cxx | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) 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(nEndRow-nStartRow+1);