sc/source/core/data/column3.cxx |   35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

New commits:
commit be11f27453f83d6a624fee898a50af471069edbd
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Mon Nov 4 14:24:26 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Nov 5 20:25:31 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>
    (cherry picked from commit 2ebb1205485cdc0bdd868ee0abe83e6a288b50da)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175997
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index f7ac967282fa..f540f8fe77be 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -2724,8 +2724,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);
@@ -2737,27 +2739,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;
             }
         }
 
@@ -2774,8 +2775,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;
                     }
                 }
             }

Reply via email to