Kaydet (Commit) 53ef918a authored tarafından Miklos Vajna's avatar Miklos Vajna

sw: lazy load table autoformats for style purposes

Commit b7138e03 (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/47820Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst efc06e9b
...@@ -323,7 +323,7 @@ class SW_DLLPUBLIC SwDoc final ...@@ -323,7 +323,7 @@ class SW_DLLPUBLIC SwDoc final
css::uno::Reference<css::container::XNameContainer> m_xTemplateToProjectCache; css::uno::Reference<css::container::XNameContainer> m_xTemplateToProjectCache;
/// Table styles (autoformats that are applied with table changes). /// 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 /// Cell Styles not assigned to a Table Style
std::unique_ptr<SwCellStyleTable> mpCellStyles; std::unique_ptr<SwCellStyleTable> mpCellStyles;
private: private:
...@@ -1235,8 +1235,13 @@ public: ...@@ -1235,8 +1235,13 @@ public:
bool GetTableAutoFormat( const SwSelBoxes& rBoxes, SwTableAutoFormat& rGet ); bool GetTableAutoFormat( const SwSelBoxes& rBoxes, SwTableAutoFormat& rGet );
/// Return the available table styles. /// Return the available table styles.
SwTableAutoFormatTable& GetTableStyles() { return *mpTableStyles.get(); } SwTableAutoFormatTable& GetTableStyles();
const SwTableAutoFormatTable& GetTableStyles() const { return *mpTableStyles.get(); } 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. // Create a new table style. Tracked by Undo.
SwTableAutoFormat* MakeTableStyle(const OUString& rName, bool bBroadcast = false); SwTableAutoFormat* MakeTableStyle(const OUString& rName, bool bBroadcast = false);
// Delete table style named rName. Tracked by undo. // Delete table style named rName. Tracked by undo.
......
...@@ -257,7 +257,7 @@ SwDoc::SwDoc() ...@@ -257,7 +257,7 @@ SwDoc::SwDoc()
mpStyleAccess( nullptr ), mpStyleAccess( nullptr ),
mpLayoutCache( nullptr ), mpLayoutCache( nullptr ),
mpGrammarContact(createGrammarContact()), mpGrammarContact(createGrammarContact()),
mpTableStyles(new SwTableAutoFormatTable), m_pTableStyles(nullptr),
mpCellStyles(new SwCellStyleTable), mpCellStyles(new SwCellStyleTable),
m_pXmlIdRegistry(), m_pXmlIdRegistry(),
mReferenceCount(0), mReferenceCount(0),
...@@ -373,8 +373,6 @@ SwDoc::SwDoc() ...@@ -373,8 +373,6 @@ SwDoc::SwDoc()
} }
mnRsidRoot = mnRsid; mnRsidRoot = mnRsid;
mpTableStyles->Load();
getIDocumentState().ResetModified(); getIDocumentState().ResetModified();
} }
......
...@@ -3865,6 +3865,16 @@ bool SwDoc::GetTableAutoFormat( const SwSelBoxes& rBoxes, SwTableAutoFormat& rGe ...@@ -3865,6 +3865,16 @@ bool SwDoc::GetTableAutoFormat( const SwSelBoxes& rBoxes, SwTableAutoFormat& rGe
return true; return true;
} }
SwTableAutoFormatTable& SwDoc::GetTableStyles()
{
if (!m_pTableStyles)
{
m_pTableStyles.reset(new SwTableAutoFormatTable);
m_pTableStyles->Load();
}
return *m_pTableStyles.get();
}
OUString SwDoc::GetUniqueTableName() const OUString SwDoc::GetUniqueTableName() const
{ {
if( IsInMailMerge()) if( IsInMailMerge())
......
...@@ -695,6 +695,9 @@ sal_Int32 lcl_GetCountOrName<SfxStyleFamily::Pseudo>(const SwDoc& rDoc, OUString ...@@ -695,6 +695,9 @@ sal_Int32 lcl_GetCountOrName<SfxStyleFamily::Pseudo>(const SwDoc& rDoc, OUString
template<> template<>
sal_Int32 lcl_GetCountOrName<SfxStyleFamily::Table>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex) 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 auto pAutoFormats = &rDoc.GetTableStyles();
const sal_Int32 nCount = pAutoFormats->size(); const sal_Int32 nCount = pAutoFormats->size();
if (0 <= nIndex && nIndex < nCount) if (0 <= nIndex && nIndex < nCount)
......
...@@ -3039,18 +3039,21 @@ SfxStyleSheetBase* SwStyleSheetIterator::First() ...@@ -3039,18 +3039,21 @@ SfxStyleSheetBase* SwStyleSheetIterator::First()
nSearchFamily == SfxStyleFamily::All ) nSearchFamily == SfxStyleFamily::All )
{ {
const auto& aTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap(); const auto& aTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap();
const SwTableAutoFormatTable& rTableStyles = rDoc.GetTableStyles(); if (rDoc.HasTableStyles())
for(size_t i = 0; i < rTableStyles.size(); ++i)
{ {
const SwTableAutoFormat& rTableStyle = rTableStyles[i]; const SwTableAutoFormatTable& rTableStyles = rDoc.GetTableStyles();
for(size_t nBoxFormat = 0; nBoxFormat < aTableTemplateMap.size(); ++nBoxFormat) for(size_t i = 0; i < rTableStyles.size(); ++i)
{ {
const sal_uInt32 nBoxIndex = aTableTemplateMap[nBoxFormat]; const SwTableAutoFormat& rTableStyle = rTableStyles[i];
const SwBoxAutoFormat& rBoxFormat = rTableStyle.GetBoxFormat(nBoxIndex); for(size_t nBoxFormat = 0; nBoxFormat < aTableTemplateMap.size(); ++nBoxFormat)
OUString sBoxFormatName; {
SwStyleNameMapper::FillProgName(rTableStyle.GetName(), sBoxFormatName, SwGetPoolIdFromName::CellStyle); const sal_uInt32 nBoxIndex = aTableTemplateMap[nBoxFormat];
sBoxFormatName += rTableStyle.GetTableTemplateCellSubName(rBoxFormat); const SwBoxAutoFormat& rBoxFormat = rTableStyle.GetBoxFormat(nBoxIndex);
aLst.Append( cCELLSTYLE, sBoxFormatName ); OUString sBoxFormatName;
SwStyleNameMapper::FillProgName(rTableStyle.GetName(), sBoxFormatName, SwGetPoolIdFromName::CellStyle);
sBoxFormatName += rTableStyle.GetTableTemplateCellSubName(rBoxFormat);
aLst.Append( cCELLSTYLE, sBoxFormatName );
}
} }
} }
const SwCellStyleTable& rCellStyles = rDoc.GetCellStyles(); const SwCellStyleTable& rCellStyles = rDoc.GetCellStyles();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment