summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2018-01-12 17:08:31 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-01-13 01:05:09 +0100
commit53ef918a6839c8d587dec1bb635e6b39397c53d0 (patch)
tree92cefdb80b6b1dc7bfb9400b64c90301b3c5c7e1 /sw
parentefc06e9bb696110350ab3e14344de53db992280e (diff)
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 <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/doc.hxx11
-rw-r--r--sw/source/core/doc/docnew.cxx4
-rw-r--r--sw/source/core/docnode/ndtbl.cxx10
-rw-r--r--sw/source/core/unocore/unostyle.cxx3
-rw-r--r--sw/source/uibase/app/docstyle.cxx23
5 files changed, 35 insertions, 16 deletions
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();