diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-03-07 12:23:26 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-03-07 16:49:52 +0100 |
commit | 06d444e9a102569aa6cf429079036fc95482cc7f (patch) | |
tree | 7c57723581c380d8e45046c5b258a9722dcbdeb2 | |
parent | 241d855f79d4e4b560a127ccdbcaa6b32297f52d (diff) |
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.grandin@collabora.co.uk>
-rw-r--r-- | editeng/source/editeng/impedit5.cxx | 12 | ||||
-rw-r--r-- | include/svl/SfxBroadcaster.hxx | 3 | ||||
-rw-r--r-- | include/svl/style.hxx | 2 | ||||
-rw-r--r-- | svl/source/items/style.cxx | 4 | ||||
-rw-r--r-- | svl/source/notify/SfxBroadcaster.cxx | 1 | ||||
-rw-r--r-- | svx/source/sdr/properties/textproperties.cxx | 4 | ||||
-rw-r--r-- | svx/source/svdraw/svdotxat.cxx | 11 |
7 files changed, 25 insertions, 12 deletions
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); + } } } } |