[Libreoffice-commits] core.git: Branch 'libreoffice-7-2' - writerfilter/source
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Fri Jun 18 07:34:34 UTC 2021
writerfilter/source/dmapper/DomainMapper.cxx | 10 +++++
writerfilter/source/dmapper/DomainMapper.hxx | 3 +
writerfilter/source/dmapper/DomainMapper_Impl.cxx | 37 ++++++++++++++++++++++
writerfilter/source/dmapper/DomainMapper_Impl.hxx | 5 ++
writerfilter/source/dmapper/StyleSheetTable.cxx | 22 +------------
5 files changed, 58 insertions(+), 19 deletions(-)
New commits:
commit 87d5ccb0503e856819ae7528d11e233ad642714f
Author: Noel Grandin <noel at peralex.com>
AuthorDate: Thu Jun 17 18:44:01 2021 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Jun 18 09:34:00 2021 +0200
tdf#135316 docx open performance, cache next character style name
so we don't have to scan the list repeatedly, which is O(n^2)
This takes my load time from 37s to 22s
Change-Id: I0df2f2ace82f5cd6287c7ded796b02c5242269ec
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117396
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
(cherry picked from commit ecbdb403d16f6b0aeb8b543e069e9d82adf10437)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117308
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index fd341dd4d765..39b118e108f0 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -4127,6 +4127,16 @@ void DomainMapper::commentProps(const OUString& sId, const CommentProperties& rP
m_pImpl->commentProps(sId, rProps);
}
+css::uno::Reference<css::container::XNameContainer> const & DomainMapper::GetCharacterStyles()
+{
+ return m_pImpl->GetCharacterStyles();
+}
+
+OUString DomainMapper::GetUnusedCharacterStyleName()
+{
+ return m_pImpl->GetUnusedCharacterStyleName();
+}
+
} //namespace writerfilter
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/DomainMapper.hxx b/writerfilter/source/dmapper/DomainMapper.hxx
index 086e7f695db2..e76014737cf3 100644
--- a/writerfilter/source/dmapper/DomainMapper.hxx
+++ b/writerfilter/source/dmapper/DomainMapper.hxx
@@ -133,6 +133,9 @@ public:
virtual void commentProps(const OUString& sId, const CommentProperties& rProps) override;
+ css::uno::Reference<css::container::XNameContainer> const & GetCharacterStyles();
+ OUString GetUnusedCharacterStyleName();
+
private:
// Stream
virtual void lcl_startSectionGroup() override;
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 7b2903f9f4b2..e02549daf430 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -442,6 +442,43 @@ OUString DomainMapper_Impl::GetUnusedPageStyleName()
return sPageStyleName;
}
+uno::Reference< container::XNameContainer > const & DomainMapper_Impl::GetCharacterStyles()
+{
+ if(!m_xCharacterStyles.is())
+ {
+ uno::Reference< style::XStyleFamiliesSupplier > xSupplier( m_xTextDocument, uno::UNO_QUERY );
+ if (xSupplier.is())
+ xSupplier->getStyleFamilies()->getByName("CharacterStyles") >>= m_xCharacterStyles;
+ }
+ return m_xCharacterStyles;
+}
+
+OUString DomainMapper_Impl::GetUnusedCharacterStyleName()
+{
+ static const char cListLabel[] = "ListLabel ";
+ if (!m_xNextUnusedCharacterStyleNo)
+ {
+ //search for all character styles with the name sListLabel + <index>
+ const uno::Sequence< OUString > aCharacterStyleNames = GetCharacterStyles()->getElementNames();
+ sal_Int32 nMaxIndex = 0;
+ for ( const auto& rStyleName : aCharacterStyleNames )
+ {
+ OUString sSuffix;
+ if ( rStyleName.startsWith( cListLabel, &sSuffix ) )
+ {
+ sal_Int32 nSuffix = sSuffix.toInt32();
+ if( nSuffix > 0 && nSuffix > nMaxIndex )
+ nMaxIndex = nSuffix;
+ }
+ }
+ m_xNextUnusedCharacterStyleNo = nMaxIndex + 1;
+ }
+
+ OUString sPageStyleName = cListLabel + OUString::number( *m_xNextUnusedCharacterStyleNo );
+ *m_xNextUnusedCharacterStyleNo = *m_xNextUnusedCharacterStyleNo + 1;
+ return sPageStyleName;
+}
+
uno::Reference< text::XText > const & DomainMapper_Impl::GetBodyText()
{
if(!m_xBodyText.is())
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 99d266968c72..5212653dcd47 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -458,6 +458,9 @@ private:
css::uno::Reference<css::container::XNameContainer> m_xPageStyles1;
// cache next available number, expensive to repeatedly compute
std::optional<int> m_xNextUnusedPageStyleNo;
+ css::uno::Reference<css::container::XNameContainer> m_xCharacterStyles;
+ // cache next available number, expensive to repeatedly compute
+ std::optional<int> m_xNextUnusedCharacterStyleNo;
css::uno::Reference<css::text::XText> m_xBodyText;
css::uno::Reference<css::text::XTextContent> m_xEmbedded;
@@ -631,6 +634,8 @@ public:
css::uno::Reference<css::container::XNameContainer> const & GetPageStyles();
OUString GetUnusedPageStyleName();
+ css::uno::Reference<css::container::XNameContainer> const & GetCharacterStyles();
+ OUString GetUnusedCharacterStyleName();
css::uno::Reference<css::text::XText> const & GetBodyText();
const css::uno::Reference<css::lang::XMultiServiceFactory>& GetTextFactory() const
{
diff --git a/writerfilter/source/dmapper/StyleSheetTable.cxx b/writerfilter/source/dmapper/StyleSheetTable.cxx
index e1329da95852..361914a60aea 100644
--- a/writerfilter/source/dmapper/StyleSheetTable.cxx
+++ b/writerfilter/source/dmapper/StyleSheetTable.cxx
@@ -1602,26 +1602,10 @@ OUString StyleSheetTable::getOrCreateCharStyle( PropertyValueVector_t& rCharProp
// Don't try to reuse an existing character style if requested.
if( !sListLabel.isEmpty() && !bAlwaysCreate)
return sListLabel;
- const char cListLabel[] = "ListLabel ";
- uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
- uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies();
- uno::Reference<container::XNameContainer> xCharStyles;
- xStyleFamilies->getByName("CharacterStyles") >>= xCharStyles;
- //search for all character styles with the name sListLabel + <index>
- sal_Int32 nStyleFound = 0;
- const uno::Sequence< OUString > aStyleNames = xCharStyles->getElementNames();
- for( const auto& rStyleName : aStyleNames )
- {
- OUString sSuffix;
- if( rStyleName.startsWith( cListLabel, &sSuffix ) )
- {
- sal_Int32 nSuffix = sSuffix.toInt32();
- if( nSuffix > 0 && nSuffix > nStyleFound )
- nStyleFound = nSuffix;
- }
- }
- sListLabel = cListLabel + OUString::number( ++nStyleFound );
+
//create a new one otherwise
+ const uno::Reference< container::XNameContainer >& xCharStyles = m_pImpl->m_rDMapper.GetCharacterStyles();
+ sListLabel = m_pImpl->m_rDMapper.GetUnusedCharacterStyleName();
uno::Reference< lang::XMultiServiceFactory > xDocFactory( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
try
{
More information about the Libreoffice-commits
mailing list