include/svl/IndexedStyleSheets.hxx      |    1 
 include/svl/style.hxx                   |    1 
 svl/source/items/IndexedStyleSheets.cxx |   12 ++++++++++
 svl/source/items/style.cxx              |   36 ++++++++++++++++++--------------
 4 files changed, 35 insertions(+), 15 deletions(-)

New commits:
commit a08d08f5f83696296fa7e12b3ee202f138b5c534
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Apr 17 14:41:48 2024 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue May 7 10:09:05 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>
    (cherry picked from commit 5060893f0b69c094beae73ab1a0926e3feb249b2)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166901
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/include/svl/IndexedStyleSheets.hxx 
b/include/svl/IndexedStyleSheets.hxx
index 910acd9e2566..c58a4b736703 100644
--- a/include/svl/IndexedStyleSheets.hxx
+++ b/include/svl/IndexedStyleSheets.hxx
@@ -144,6 +144,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 db265fc98340..64cb723f3649 100644
--- a/include/svl/style.hxx
+++ b/include/svl/style.hxx
@@ -280,6 +280,7 @@ public:
                                           const OUString &rParent);
 
     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 57e2dddbf1c1..3761f0e427ef 100644
--- a/svl/source/items/IndexedStyleSheets.cxx
+++ b/svl/source/items/IndexedStyleSheets.cxx
@@ -82,6 +82,18 @@ sal_Int32 IndexedStyleSheets::GetNumberOfStyleSheets() const
     return mStyleSheets.size();
 }
 
+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 4f4ae926f461..a6e5b130adda 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;
 }
 
@@ -915,6 +915,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
 {

Reply via email to