sc/inc/patattr.hxx              |    4 +++-
 sc/source/core/data/patattr.cxx |   14 ++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

New commits:
commit 8ec8d592e31aebe19075e9f89c4c2c7abcf8d420
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Jun 22 09:38:50 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Jun 23 10:36:53 2023 +0200

    Speed up scrolling through large document with lots of patterns
    
    Cache visibility for use in ScPatternAttr::IsVisible
    
    Change-Id: Ia248a06b876b53115bbc3017d97538bbbc03830d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153482
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/inc/patattr.hxx b/sc/inc/patattr.hxx
index ba15cfb1dd27..4d7df0c6ac23 100644
--- a/sc/inc/patattr.hxx
+++ b/sc/inc/patattr.hxx
@@ -54,6 +54,7 @@ class SC_DLLPUBLIC ScPatternAttr final : public SfxSetItem
 {
     std::optional<OUString>  pName;
     mutable std::optional<sal_uInt32> mxHashCode;
+    mutable std::optional<bool> mxVisible;
     ScStyleSheet*              pStyle;
     sal_uInt64                 mnKey;
 public:
@@ -184,11 +185,12 @@ public:
     // TODO: tdf#135215: This is a band-aid to detect changes and invalidate 
the hash,
     // a proper way would be probably to override SfxItemSet::Changed(), but 
6cb400f41df0dd10
     // hardcoded SfxSetItem to contain SfxItemSet.
-    SfxItemSet& GetItemSet() { mxHashCode.reset(); return 
SfxSetItem::GetItemSet(); }
+    SfxItemSet& GetItemSet() { mxHashCode.reset(); mxVisible.reset(); return 
SfxSetItem::GetItemSet(); }
     using SfxSetItem::GetItemSet;
 
 private:
     void                    CalcHashCode() const;
+    bool                    CalcVisible() const;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/patattr.cxx b/sc/source/core/data/patattr.cxx
index 706ab6ae5c19..199d41ab25f1 100644
--- a/sc/source/core/data/patattr.cxx
+++ b/sc/source/core/data/patattr.cxx
@@ -981,6 +981,7 @@ void ScPatternAttr::GetFromEditItemSet( const SfxItemSet* 
pEditSet )
         return;
     GetFromEditItemSet( GetItemSet(), *pEditSet );
     mxHashCode.reset();
+    mxVisible.reset();
 }
 
 void ScPatternAttr::FillEditParaItems( SfxItemSet* pEditSet ) const
@@ -1024,6 +1025,7 @@ void ScPatternAttr::DeleteUnchanged( const ScPatternAttr* 
pOldAttrs )
                 {
                     rThisSet.ClearItem( nSubWhich );
                     mxHashCode.reset();
+                    mxVisible.reset();
                 }
             }
             else if ( eOldState != SfxItemState::DONTCARE )
@@ -1033,6 +1035,7 @@ void ScPatternAttr::DeleteUnchanged( const ScPatternAttr* 
pOldAttrs )
                 {
                     rThisSet.ClearItem( nSubWhich );
                     mxHashCode.reset();
+                    mxVisible.reset();
                 }
             }
         }
@@ -1054,6 +1057,7 @@ void ScPatternAttr::ClearItems( const sal_uInt16* pWhich )
     for (sal_uInt16 i=0; pWhich[i]; i++)
         rSet.ClearItem(pWhich[i]);
     mxHashCode.reset();
+    mxVisible.reset();
 }
 
 static SfxStyleSheetBase* lcl_CopyStyleToPool
@@ -1189,6 +1193,13 @@ ScPatternAttr* ScPatternAttr::PutInPool( ScDocument* 
pDestDoc, ScDocument* pSrcD
 }
 
 bool ScPatternAttr::IsVisible() const
+{
+    if (!mxVisible)
+        mxVisible = CalcVisible();
+    return *mxVisible;
+}
+
+bool ScPatternAttr::CalcVisible() const
 {
     const SfxItemSet& rSet = GetItemSet();
 
@@ -1312,6 +1323,7 @@ void ScPatternAttr::SetStyleSheet( ScStyleSheet* 
pNewStyle, bool bClearDirectFor
         pStyle = nullptr;
     }
     mxHashCode.reset();
+    mxVisible.reset();
 }
 
 void ScPatternAttr::UpdateStyleSheet(const ScDocument& rDoc)
@@ -1338,6 +1350,7 @@ void ScPatternAttr::UpdateStyleSheet(const ScDocument& 
rDoc)
     else
         pStyle = nullptr;
     mxHashCode.reset();
+    mxVisible.reset();
 }
 
 void ScPatternAttr::StyleToName()
@@ -1350,6 +1363,7 @@ void ScPatternAttr::StyleToName()
         pStyle = nullptr;
         GetItemSet().SetParent( nullptr );
         mxHashCode.reset();
+        mxVisible.reset();
     }
 }
 

Reply via email to