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 <jluth@mail.com>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins
This commit is contained in:
Justin Luth
2024-11-29 21:16:52 +01:00
parent 6c0b18e06a
commit eaef1432bd
+15 -10
View File
@@ -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);