sw/inc/doc.hxx                      |   11 ++++++++---
 sw/source/core/doc/docnew.cxx       |    4 +---
 sw/source/core/docnode/ndtbl.cxx    |   10 ++++++++++
 sw/source/core/unocore/unostyle.cxx |    3 +++
 sw/source/uibase/app/docstyle.cxx   |   23 +++++++++++++----------
 5 files changed, 35 insertions(+), 16 deletions(-)

New commits:
commit 53ef918a6839c8d587dec1bb635e6b39397c53d0
Author: Miklos Vajna <vmik...@collabora.co.uk>
Date:   Fri Jan 12 17:08:31 2018 +0100

    sw: lazy load table autoformats for style purposes
    
    Commit b7138e03ebc8a33258c099c5cf6015970646a40e (GSoC Writer Table
    Styles; Import bugfix, 2016-07-26) changed the SwDoc ctor to always load
    the table autoformats, which is expensive for simple documents. Avoid
    the load in the ctor by switching to lazy-load and adding a way to count
    the number of styles without loading the autoformats when there would be
    none.
    
    (mpTableStyles -> m_pTableStyles was only necessary to see if there is
    access outside GetTableStyles() to this member, but there were not any.)
    
    Times for 100 hello world inputs: 3863 -> 2753 ms is spent in XHTML-load + 
ODT
    export + close (71% of original).
    
    Change-Id: I6737e7712c775573b56c8b0566e8e7fb615edee6
    Reviewed-on: https://gerrit.libreoffice.org/47820
    Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk>
    Tested-by: Jenkins <c...@libreoffice.org>

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 1a680165d9e7..da91f08d4375 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -323,7 +323,7 @@ class SW_DLLPUBLIC SwDoc final
     css::uno::Reference<css::container::XNameContainer> 
m_xTemplateToProjectCache;
 
     /// Table styles (autoformats that are applied with table changes).
-    std::unique_ptr<SwTableAutoFormatTable> mpTableStyles;
+    std::unique_ptr<SwTableAutoFormatTable> m_pTableStyles;
     /// Cell Styles not assigned to a Table Style
     std::unique_ptr<SwCellStyleTable> mpCellStyles;
 private:
@@ -1235,8 +1235,13 @@ public:
     bool GetTableAutoFormat( const SwSelBoxes& rBoxes, SwTableAutoFormat& rGet 
);
 
     /// Return the available table styles.
-    SwTableAutoFormatTable& GetTableStyles() { return *mpTableStyles.get(); }
-    const SwTableAutoFormatTable& GetTableStyles() const { return 
*mpTableStyles.get(); }
+    SwTableAutoFormatTable& GetTableStyles();
+    const SwTableAutoFormatTable& GetTableStyles() const
+    {
+        return const_cast<SwDoc*>(this)->GetTableStyles();
+    }
+    /// Counts table styles without triggering lazy-load of them.
+    bool HasTableStyles() const { return m_pTableStyles != nullptr; }
     // Create a new table style. Tracked by Undo.
     SwTableAutoFormat* MakeTableStyle(const OUString& rName, bool bBroadcast = 
false);
     // Delete table style named rName. Tracked by undo.
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index 2fae0c3597d4..ec41a235f125 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -257,7 +257,7 @@ SwDoc::SwDoc()
     mpStyleAccess( nullptr ),
     mpLayoutCache( nullptr ),
     mpGrammarContact(createGrammarContact()),
-    mpTableStyles(new SwTableAutoFormatTable),
+    m_pTableStyles(nullptr),
     mpCellStyles(new SwCellStyleTable),
     m_pXmlIdRegistry(),
     mReferenceCount(0),
@@ -373,8 +373,6 @@ SwDoc::SwDoc()
     }
     mnRsidRoot = mnRsid;
 
-    mpTableStyles->Load();
-
     getIDocumentState().ResetModified();
 }
 
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index cb10bdb711f7..69dc8686084b 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -3865,6 +3865,16 @@ bool SwDoc::GetTableAutoFormat( const SwSelBoxes& 
rBoxes, SwTableAutoFormat& rGe
     return true;
 }
 
+SwTableAutoFormatTable& SwDoc::GetTableStyles()
+{
+    if (!m_pTableStyles)
+    {
+        m_pTableStyles.reset(new SwTableAutoFormatTable);
+        m_pTableStyles->Load();
+    }
+    return *m_pTableStyles.get();
+}
+
 OUString SwDoc::GetUniqueTableName() const
 {
     if( IsInMailMerge())
diff --git a/sw/source/core/unocore/unostyle.cxx 
b/sw/source/core/unocore/unostyle.cxx
index d7d3eb9b3fc2..b83289107d26 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -695,6 +695,9 @@ sal_Int32 lcl_GetCountOrName<SfxStyleFamily::Pseudo>(const 
SwDoc& rDoc, OUString
 template<>
 sal_Int32 lcl_GetCountOrName<SfxStyleFamily::Table>(const SwDoc& rDoc, 
OUString* pString, sal_Int32 nIndex)
 {
+    if (!rDoc.HasTableStyles())
+        return 0;
+
     const auto pAutoFormats = &rDoc.GetTableStyles();
     const sal_Int32 nCount = pAutoFormats->size();
     if (0 <= nIndex && nIndex < nCount)
diff --git a/sw/source/uibase/app/docstyle.cxx 
b/sw/source/uibase/app/docstyle.cxx
index a43fc90265dd..dbb7f0316241 100644
--- a/sw/source/uibase/app/docstyle.cxx
+++ b/sw/source/uibase/app/docstyle.cxx
@@ -3039,18 +3039,21 @@ SfxStyleSheetBase*  SwStyleSheetIterator::First()
         nSearchFamily == SfxStyleFamily::All )
     {
         const auto& aTableTemplateMap = 
SwTableAutoFormat::GetTableTemplateMap();
-        const SwTableAutoFormatTable& rTableStyles = rDoc.GetTableStyles();
-        for(size_t i = 0; i < rTableStyles.size(); ++i)
+        if (rDoc.HasTableStyles())
         {
-            const SwTableAutoFormat& rTableStyle = rTableStyles[i];
-            for(size_t nBoxFormat = 0; nBoxFormat < aTableTemplateMap.size(); 
++nBoxFormat)
+            const SwTableAutoFormatTable& rTableStyles = rDoc.GetTableStyles();
+            for(size_t i = 0; i < rTableStyles.size(); ++i)
             {
-                const sal_uInt32 nBoxIndex = aTableTemplateMap[nBoxFormat];
-                const SwBoxAutoFormat& rBoxFormat = 
rTableStyle.GetBoxFormat(nBoxIndex);
-                OUString sBoxFormatName;
-                SwStyleNameMapper::FillProgName(rTableStyle.GetName(), 
sBoxFormatName, SwGetPoolIdFromName::CellStyle);
-                sBoxFormatName += 
rTableStyle.GetTableTemplateCellSubName(rBoxFormat);
-                aLst.Append( cCELLSTYLE, sBoxFormatName );
+                const SwTableAutoFormat& rTableStyle = rTableStyles[i];
+                for(size_t nBoxFormat = 0; nBoxFormat < 
aTableTemplateMap.size(); ++nBoxFormat)
+                {
+                    const sal_uInt32 nBoxIndex = aTableTemplateMap[nBoxFormat];
+                    const SwBoxAutoFormat& rBoxFormat = 
rTableStyle.GetBoxFormat(nBoxIndex);
+                    OUString sBoxFormatName;
+                    SwStyleNameMapper::FillProgName(rTableStyle.GetName(), 
sBoxFormatName, SwGetPoolIdFromName::CellStyle);
+                    sBoxFormatName += 
rTableStyle.GetTableTemplateCellSubName(rBoxFormat);
+                    aLst.Append( cCELLSTYLE, sBoxFormatName );
+                }
             }
         }
         const SwCellStyleTable& rCellStyles = rDoc.GetCellStyles();
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to