sc/source/core/data/column3.cxx | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-)
New commits: commit 2ebb1205485cdc0bdd868ee0abe83e6a288b50da Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Mon Nov 4 14:24:26 2024 +0200 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Mon Nov 4 14:31:16 2024 +0100 tdf#163667 speed up spreadsheet with lots of cond formatting (II) Attempt to avoid the cost of GetCondResult when dealing with large runs of identical cells This restructures my caching code to increase the chance of hitting the cache. Change-Id: Ic83ff467be05fd645c80276708adb627c6b297d4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176007 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 1021846f3075..15c70f0bade3 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -2725,8 +2725,10 @@ void ScColumn::GetBackColorFilterEntries(SCROW nRow1, SCROW nRow2, ScFilterEntri ScAddress aCell(GetCol(), 0, GetTab()); ScDocument& rDoc = GetDoc(); + // cache the output of GetCondResult const ScPatternAttr* pPrevPattern = nullptr; ScRefCellValue aPrevCellValue; + Color aPrevPatternColor; while (nRow1 <= nRow2) { aCell.SetRow(nRow1); @@ -2738,27 +2740,26 @@ void ScColumn::GetBackColorFilterEntries(SCROW nRow1, SCROW nRow2, ScFilterEntri if (pPattern) { - // Speed up processing when dealing with runs of identical cells. We only - // care about collecting unique colors, so no need to process a cell if the result - // will be the same as the previous cell. - // Which we can only do if there is no conditional format to override the color on this cell. - if (!pCondFormat) + if (!pPattern->GetItem(ATTR_CONDITIONAL).GetCondFormatData().empty()) { + // Speed up processing when dealing with runs of identical cells. This avoids + // an expensive GetCondResult call. ScRefCellValue aCellValue = GetCellValue(nRow1); if (pPrevPattern == pPattern && aCellValue == aPrevCellValue) { - nRow1++; - continue; + aBackColor = aPrevPatternColor; + bCondBackColor = true; + } + else + { + const SfxItemSet* pCondSet = rDoc.GetCondResult(GetCol(), nRow1, GetTab()); + const SvxBrushItem* pBrush = &pPattern->GetItem(ATTR_BACKGROUND, pCondSet); + aBackColor = pBrush->GetColor(); + bCondBackColor = true; + aPrevCellValue = aCellValue; + pPrevPattern = pPattern; + aPrevPatternColor = aBackColor; } - aPrevCellValue = aCellValue; - pPrevPattern = pPattern; - } - if (!pPattern->GetItem(ATTR_CONDITIONAL).GetCondFormatData().empty()) - { - const SfxItemSet* pCondSet = rDoc.GetCondResult(GetCol(), nRow1, GetTab()); - const SvxBrushItem* pBrush = &pPattern->GetItem(ATTR_BACKGROUND, pCondSet); - aBackColor = pBrush->GetColor(); - bCondBackColor = true; } } @@ -2775,8 +2776,6 @@ void ScColumn::GetBackColorFilterEntries(SCROW nRow1, SCROW nRow2, ScFilterEntri { aBackColor = *oColor; bCondBackColor = true; - // we are overriding the color, so we need to clear the one-item cache. - pPrevPattern = nullptr; } } }