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>
diff --git a/editeng/source/editeng/impedit5.cxx b/editeng/source/editeng/impedit5.cxx
index 6b1a303..396e529 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 b026f4c..f4ba226 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 75ebe788..058d99c 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 0b00549..104cb79 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 419c535..c9a26aa 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 42a71dd..220d6a5 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 6b39887..7e696f6 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);
                }
            }
        }
    }