editeng/source/editeng/impedit5.cxx          |   12 ++++++------
 include/svl/SfxBroadcaster.hxx               |    3 +++
 include/svl/style.hxx                        |    2 ++
 svl/source/items/IndexedStyleSheets.cxx      |    4 ++--
 svl/source/items/style.cxx                   |    4 ++++
 svl/source/notify/SfxBroadcaster.cxx         |    1 +
 svx/source/sdr/properties/textproperties.cxx |    4 ++--
 svx/source/svdraw/svdotxat.cxx               |   11 +++++++----
 8 files changed, 27 insertions(+), 14 deletions(-)

New commits:
commit 34017b14d866e99aff466ff200b60b3e2d509a30
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Mar 7 12:48:00 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Mar 7 16:50:00 2024 +0100

    tdf#158773 reduce time spent in IndexedStyleSheets::Reindex
    
    no need to de-allocate and then re-allocate the vectors inside
    mStyleSheetPositionsByFamily
    
    Change-Id: I3ad10173d9f3ba252619667afe13250045c943c5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164529
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/svl/source/items/IndexedStyleSheets.cxx 
b/svl/source/items/IndexedStyleSheets.cxx
index 57e2dddbf1c1..c4b879d4f9c2 100644
--- a/svl/source/items/IndexedStyleSheets.cxx
+++ b/svl/source/items/IndexedStyleSheets.cxx
@@ -64,9 +64,9 @@ void
 IndexedStyleSheets::Reindex()
 {
     mPositionsByName.clear();
-    mStyleSheetPositionsByFamily.clear();
+    mStyleSheetPositionsByFamily.resize(NUMBER_OF_FAMILIES);
     for (size_t i = 0; i < NUMBER_OF_FAMILIES; i++) {
-        mStyleSheetPositionsByFamily.emplace_back();
+        mStyleSheetPositionsByFamily[i].clear();
     }
 
     sal_Int32 i = 0;
commit 06d444e9a102569aa6cf429079036fc95482cc7f
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Mar 7 12:23:26 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Mar 7 16:49:52 2024 +0100

    tdf#158773 reduce dynamic_cast'ing in TextProperties::Notify
    
    Change-Id: If4a68433c57fdf3da56891fa0b4be6f8a991d929
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164528
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/editeng/source/editeng/impedit5.cxx 
b/editeng/source/editeng/impedit5.cxx
index 6b1a303ae8da..396e529c514d 100644
--- a/editeng/source/editeng/impedit5.cxx
+++ b/editeng/source/editeng/impedit5.cxx
@@ -158,15 +158,15 @@ void ImpEditEngine::Notify( SfxBroadcaster& rBC, const 
SfxHint& rHint )
             SfxStyleSheet* pStyle = static_cast<SfxStyleSheet*>( 
pStyleSheetHint->GetStyleSheet() );
             UpdateParagraphsWithStyleSheet( pStyle );
         }
-        else if ( nId == SfxHintId::Dying )
+        else if ( nId == SfxHintId::Dying && rBC.IsSfxStyleSheet() )
         {
-            if ( auto pStyle = dynamic_cast< SfxStyleSheet* >(&rBC) )
-                RemoveStyleFromParagraphs( pStyle );
+            auto pStyle = static_cast< SfxStyleSheet* >(&rBC);
+            RemoveStyleFromParagraphs( pStyle );
         }
-        else if ( nId == SfxHintId::DataChanged )
+        else if ( nId == SfxHintId::DataChanged && rBC.IsSfxStyleSheet())
         {
-            if ( auto pStyle = dynamic_cast< SfxStyleSheet* >(&rBC) )
-                UpdateParagraphsWithStyleSheet( pStyle );
+            auto pStyle = static_cast< SfxStyleSheet* >(&rBC);
+            UpdateParagraphsWithStyleSheet( pStyle );
         }
     }
     if (rHint.GetId() == SfxHintId::Dying && dynamic_cast<const 
SfxApplication*>(&rBC))
diff --git a/include/svl/SfxBroadcaster.hxx b/include/svl/SfxBroadcaster.hxx
index b026f4c7e4a6..f4ba2264a066 100644
--- a/include/svl/SfxBroadcaster.hxx
+++ b/include/svl/SfxBroadcaster.hxx
@@ -57,6 +57,9 @@ public:
         return true to break the loop.  */
     void  ForAllListeners(std::function<bool(SfxListener*)> f) const;
 
+    /** used to avoid dynamic_cast cost */
+    virtual bool IsSfxStyleSheet() const;
+
     friend class SfxListener;
     friend class ::SfxBroadcasterTest;
 };
diff --git a/include/svl/style.hxx b/include/svl/style.hxx
index 75ebe788c737..058d99c376c1 100644
--- a/include/svl/style.hxx
+++ b/include/svl/style.hxx
@@ -295,6 +295,8 @@ public:
 
     virtual bool        SetParent( const OUString& ) override;
 
+    virtual bool        IsSfxStyleSheet() const override;
+
 protected:
     virtual             ~SfxStyleSheet() override;
 };
diff --git a/svl/source/items/style.cxx b/svl/source/items/style.cxx
index 0b0054984a4c..104cb793cc6d 100644
--- a/svl/source/items/style.cxx
+++ b/svl/source/items/style.cxx
@@ -856,6 +856,10 @@ bool SfxStyleSheet::isUsedByModel() const
     return IsUsed();
 }
 
+bool SfxStyleSheet::IsSfxStyleSheet() const
+{
+    return true;
+}
 
 SfxStyleSheetPool::SfxStyleSheetPool( SfxItemPool const& rSet)
 : SfxStyleSheetBasePool( const_cast< SfxItemPool& >( rSet ) )
diff --git a/svl/source/notify/SfxBroadcaster.cxx 
b/svl/source/notify/SfxBroadcaster.cxx
index 419c535f56dc..c9a26aabb7c8 100644
--- a/svl/source/notify/SfxBroadcaster.cxx
+++ b/svl/source/notify/SfxBroadcaster.cxx
@@ -149,4 +149,5 @@ size_t SfxBroadcaster::GetListenerCount() const
     return m_Listeners.size() - m_RemovedPositions.size();
 }
 
+bool SfxBroadcaster::IsSfxStyleSheet() const { return false; }
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/sdr/properties/textproperties.cxx 
b/svx/source/sdr/properties/textproperties.cxx
index 42a71dd3b1fb..220d6a528ef1 100644
--- a/svx/source/sdr/properties/textproperties.cxx
+++ b/svx/source/sdr/properties/textproperties.cxx
@@ -557,7 +557,7 @@ namespace sdr::properties
             SfxHintId nId(rHint.GetId());
             const svx::ITextProvider& rTextProvider(getTextProvider());
 
-            if(SfxHintId::DataChanged == nId && dynamic_cast<const 
SfxStyleSheet *>(&rBC) != nullptr)
+            if(SfxHintId::DataChanged == nId && rBC.IsSfxStyleSheet())
             {
                 sal_Int32 nText = rTextProvider.getTextCount();
                 while (nText--)
@@ -578,7 +578,7 @@ namespace sdr::properties
                 // #i101556# content of StyleSheet has changed -> new version
                 maVersion++;
             }
-            else if(SfxHintId::Dying == nId && dynamic_cast<const 
SfxStyleSheet *>(&rBC) != nullptr)
+            else if(SfxHintId::Dying == nId && rBC.IsSfxStyleSheet())
             {
                 sal_Int32 nText = rTextProvider.getTextCount();
                 while (nText--)
diff --git a/svx/source/svdraw/svdotxat.cxx b/svx/source/svdraw/svdotxat.cxx
index 6b39887d17f9..7e696f6b94cc 100644
--- a/svx/source/svdraw/svdotxat.cxx
+++ b/svx/source/svdraw/svdotxat.cxx
@@ -360,10 +360,13 @@ void SdrTextObj::ImpSetTextStyleSheetListeners()
     while (nNum>0) {
         nNum--;
         SfxBroadcaster* pBroadcast=GetBroadcasterJOE(nNum);
-        SfxStyleSheet* pStyle=dynamic_cast<SfxStyleSheet*>( pBroadcast );
-        if (pStyle!=nullptr && pStyle!=GetStyleSheet()) { // special case for 
stylesheet of the object
-            if (aStyleSheets.find(pStyle)==aStyleSheets.end()) {
-                EndListening(*pStyle);
+        if (pBroadcast->IsSfxStyleSheet())
+        {
+            SfxStyleSheet* pStyle = static_cast<SfxStyleSheet*>( pBroadcast );
+            if (pStyle!=GetStyleSheet()) { // special case for stylesheet of 
the object
+                if (aStyleSheets.find(pStyle)==aStyleSheets.end()) {
+                    EndListening(*pStyle);
+                }
             }
         }
     }

Reply via email to