include/svl/IndexedStyleSheets.hxx | 1 include/svl/style.hxx | 1 sc/source/filter/inc/stylesfragment.hxx | 3 -- sc/source/filter/oox/stylesfragment.cxx | 13 ++++------- svl/source/items/IndexedStyleSheets.cxx | 12 ++++++++++ svl/source/items/style.cxx | 36 ++++++++++++++++++-------------- 6 files changed, 41 insertions(+), 25 deletions(-)
New commits: commit 00c13dfcdbf34cdddb19005dba207147071f5e47 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Wed Apr 17 20:17:41 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Apr 18 08:14:17 2024 +0200 Simplify DxfContext (*) we don't need two fields, they are both serving the same purpose (*) we don't need to check for null, the field is never null Change-Id: I98c69de399ac463c9bfd32cde450941e04ac92cc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166186 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sc/source/filter/inc/stylesfragment.hxx b/sc/source/filter/inc/stylesfragment.hxx index 84ba3a0a3241..ead5a20f16db 100644 --- a/sc/source/filter/inc/stylesfragment.hxx +++ b/sc/source/filter/inc/stylesfragment.hxx @@ -101,14 +101,13 @@ class DxfContext : public WorkbookContextBase public: template< typename ParentType > explicit DxfContext( ParentType& rParent, const DxfRef& rxDxf ) : - WorkbookContextBase( rParent ), mxDxf( rxDxf ), mxExtDxf( rxDxf ) {} + WorkbookContextBase( rParent ), mxDxf( rxDxf ) {} protected: virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override; private: DxfRef mxDxf; - DxfRef mxExtDxf; }; class StylesFragment : public WorkbookFragmentBase diff --git a/sc/source/filter/oox/stylesfragment.cxx b/sc/source/filter/oox/stylesfragment.cxx index e6707704dc44..de6312b9649c 100644 --- a/sc/source/filter/oox/stylesfragment.cxx +++ b/sc/source/filter/oox/stylesfragment.cxx @@ -139,7 +139,7 @@ ContextHandlerRef XfContext::onCreateContext( sal_Int32 nElement, const Attribut ContextHandlerRef DxfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) { - if( mxDxf ) switch( getCurrentElement() ) + switch( getCurrentElement() ) { case XLS_TOKEN( dxf ): switch( nElement ) @@ -155,17 +155,14 @@ ContextHandlerRef DxfContext::onCreateContext( sal_Int32 nElement, const Attribu #endif } break; - } - if( mxExtDxf ) switch( getCurrentElement() ) - { case XLS14_TOKEN( dxf ): switch( nElement ) { - case XLS_TOKEN( font ): return new FontContext( *this, mxExtDxf->createFont() ); - case XLS_TOKEN( border ): return new BorderContext( *this, mxExtDxf->createBorder() ); - case XLS_TOKEN( fill ): return new FillContext( *this, mxExtDxf->createFill() ); - case XLS_TOKEN( numFmt ): mxExtDxf->importNumFmt( rAttribs ); break; + case XLS_TOKEN( font ): return new FontContext( *this, mxDxf->createFont() ); + case XLS_TOKEN( border ): return new BorderContext( *this, mxDxf->createBorder() ); + case XLS_TOKEN( fill ): return new FillContext( *this, mxDxf->createFill() ); + case XLS_TOKEN( numFmt ): mxDxf->importNumFmt( rAttribs ); break; } break; } commit 5060893f0b69c094beae73ab1a0926e3feb249b2 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Apr 17 14:41:48 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Apr 18 08:14:06 2024 +0200 tdf#160706 speed up loading conditional formatting rule in XLS (II) Reduce the work we do in IndexedStyleSheets::Reindex takes my test document from 117s to 48s Change-Id: I2e23b05684d0f2e3a9dc05c0a0fc4e9bbea7008d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166180 Tested-by: Noel Grandin <noel.gran...@collabora.co.uk> Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/svl/IndexedStyleSheets.hxx b/include/svl/IndexedStyleSheets.hxx index 1734c7248e04..685b958fa632 100644 --- a/include/svl/IndexedStyleSheets.hxx +++ b/include/svl/IndexedStyleSheets.hxx @@ -145,6 +145,7 @@ public: void Clear(StyleSheetDisposer& cleanup); void Reindex(); + void ReindexOnNameChange(const OUString& rOldName, const OUString& rNewName); /** Warning: counting for n starts at 0, i.e., the 0th style sheet is the first that is found. */ SfxStyleSheetBase* GetNthStyleSheetThatMatchesPredicate(sal_Int32 n, diff --git a/include/svl/style.hxx b/include/svl/style.hxx index 058d99c376c1..018da0a04e67 100644 --- a/include/svl/style.hxx +++ b/include/svl/style.hxx @@ -275,6 +275,7 @@ public: virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All ); void Reindex(); + void ReindexOnNameChange(const OUString& rOldName, const OUString& rNewName); /** Add a style sheet. * Not an actual public function. Do not call it from non-subclasses. */ diff --git a/svl/source/items/IndexedStyleSheets.cxx b/svl/source/items/IndexedStyleSheets.cxx index 351e56425036..adce9bf1dca2 100644 --- a/svl/source/items/IndexedStyleSheets.cxx +++ b/svl/source/items/IndexedStyleSheets.cxx @@ -68,6 +68,18 @@ IndexedStyleSheets::Reindex() } } +void +IndexedStyleSheets::ReindexOnNameChange(const OUString& rOldName, const OUString& rNewName) +{ + auto it = mPositionsByName.find(rOldName); + if (it != mPositionsByName.end()) + { + unsigned nPos = it->second; + mPositionsByName.erase(it); + mPositionsByName.insert(std::make_pair(rNewName, nPos)); + } +} + void IndexedStyleSheets::AddStyleSheet(const rtl::Reference< SfxStyleSheetBase >& style) { diff --git a/svl/source/items/style.cxx b/svl/source/items/style.cxx index bcd90faeaef4..8a2da70793e6 100644 --- a/svl/source/items/style.cxx +++ b/svl/source/items/style.cxx @@ -163,24 +163,24 @@ bool SfxStyleSheetBase::SetName(const OUString& rName, bool bReIndexNow) if(rName.isEmpty()) return false; - if( aName != rName ) - { - OUString aOldName = aName; - SfxStyleSheetBase *pOther = m_pPool->Find( rName, nFamily ) ; - if ( pOther && pOther != this ) - return false; + if( aName == rName ) + return true; - if ( !aName.isEmpty() ) - m_pPool->ChangeParent(aName, rName, nFamily, false); + OUString aOldName = aName; + SfxStyleSheetBase *pOther = m_pPool->Find( rName, nFamily ) ; + if ( pOther && pOther != this ) + return false; - if ( aFollow == aName ) - aFollow = rName; - aName = rName; - if (bReIndexNow) - m_pPool->Reindex(); + if ( !aName.isEmpty() ) + m_pPool->ChangeParent(aName, rName, nFamily, false); - m_pPool->Broadcast( SfxStyleSheetModifiedHint( aOldName, *this ) ); - } + if ( aFollow == aName ) + aFollow = rName; + aName = rName; + if (bReIndexNow) + m_pPool->ReindexOnNameChange(aOldName, rName); + + m_pPool->Broadcast( SfxStyleSheetModifiedHint( aOldName, *this ) ); return true; } @@ -889,6 +889,12 @@ SfxStyleSheetBasePool::Reindex() pImpl->mxIndexedStyleSheets->Reindex(); } +void +SfxStyleSheetBasePool::ReindexOnNameChange(const OUString& rOldName, const OUString& rNewName) +{ + pImpl->mxIndexedStyleSheets->ReindexOnNameChange(rOldName, rNewName); +} + const svl::IndexedStyleSheets& SfxStyleSheetBasePool::GetIndexedStyleSheets() const {