sw/inc/unoxstyle.hxx                |    3 +++
 sw/source/core/unocore/unostyle.cxx |   10 +++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

New commits:
commit afe19beb79c3f88e42fd4b1d9b87cd324092197f
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Aug 15 18:51:28 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Aug 15 22:04:36 2024 +0200

    tdf#158556 cache SwDocStyleSheet
    
    so we dont keep creating it again. Shaves 3% off the load time.
    
    Change-Id: Id67927f854d55769f76e56c6bc9a9e9bb05eea6c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171919
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/unoxstyle.hxx b/sw/inc/unoxstyle.hxx
index 6ccade4592ad..b33a8e4130b7 100644
--- a/sw/inc/unoxstyle.hxx
+++ b/sw/inc/unoxstyle.hxx
@@ -43,6 +43,7 @@ class SwDoc;
 class SfxItemPropertySet;
 class SwDocShell;
 class SwXNumberingRules;
+class SwDocStyleSheet;
 
 class SAL_DLLPUBLIC_RTTI SwXStyle
     : public cppu::ImplInheritanceHelper<
@@ -57,6 +58,8 @@ class SAL_DLLPUBLIC_RTTI SwXStyle
     bool m_bIsDescriptor;
     bool m_bIsConditional;
     OUString m_sParentStyleName;
+    // cache UNO stylesheets
+    std::unordered_map<SfxStyleSheetBase*, rtl::Reference<SwDocStyleSheet>> 
maUnoStyleSheets;
 
 protected:
     SfxStyleSheetBasePool* m_pBasePool;
diff --git a/sw/source/core/unocore/unostyle.cxx 
b/sw/source/core/unocore/unostyle.cxx
index fb41a7d9364f..5c69f446d6ef 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -2433,7 +2433,15 @@ void SwXStyle::getToggleAttributes(
     assert(m_pBasePool);
     SfxStyleSheetBase* pStyleSheetBase = m_pBasePool->Find(m_sStyleName, 
m_rEntry.family());
     assert(pStyleSheetBase);
-    rtl::Reference<SwDocStyleSheet> xDocStyleSheet = new 
SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pStyleSheetBase));
+    rtl::Reference<SwDocStyleSheet> xDocStyleSheet;
+    auto it = maUnoStyleSheets.find(pStyleSheetBase);
+    if (it != maUnoStyleSheets.end())
+        xDocStyleSheet = it->second;
+    else
+    {
+        xDocStyleSheet = new 
SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pStyleSheetBase));
+        maUnoStyleSheets.insert({pStyleSheetBase, xDocStyleSheet});
+    }
     const SfxItemSet& rItemSet(xDocStyleSheet->GetItemSet());
     assert(rItemSet.GetParent());
 

Reply via email to