include/sfx2/event.hxx                   |   12 +++++++-----
 include/svl/hint.hxx                     |    3 ++-
 sc/source/ui/app/inputwin.cxx            |    6 +++---
 sc/source/ui/docshell/docsh.cxx          |   11 ++++-------
 sc/source/ui/docshell/externalrefmgr.cxx |    6 ++----
 sc/source/ui/navipi/navipi.cxx           |    5 +++--
 sd/source/ui/view/ViewShellBase.cxx      |   10 +++++-----
 sfx2/source/appl/sfxpicklist.cxx         |    8 ++++----
 sfx2/source/doc/sfxbasemodel.cxx         |   13 +++++--------
 sfx2/source/view/viewfrm.cxx             |    4 ++--
 sfx2/source/view/viewsh.cxx              |    6 ++++--
 svx/source/form/fmundo.cxx               |    4 ++--
 sw/source/uibase/app/apphdl.cxx          |    7 ++++---
 sw/source/uibase/app/docsh2.cxx          |   15 +++++++--------
 sw/source/uibase/docvw/PostItMgr.cxx     |    5 +++--
 sw/source/uibase/uno/unoatxt.cxx         |    5 +++--
 sw/source/uibase/utlui/navipi.cxx        |    4 ++--
 17 files changed, 62 insertions(+), 62 deletions(-)

New commits:
commit 9bd3c25165447fb80b8f8cb8761943294e0a1502
Author:     Caolán McNamara <[email protected]>
AuthorDate: Fri Oct 6 09:31:28 2023 +0100
Commit:     Noel Grandin <[email protected]>
CommitDate: Fri Oct 6 14:11:41 2023 +0200

    Related: cool#7373 add an SfxHintId::ThisIsAnSfxEventHint
    
    to avoid cost of dynamic_cast of SdrHint to SfxEventHint
    
    Change-Id: Ie0366b7d7ba828d8ffabeed4d65d7c7b275a3ed4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157620
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/include/sfx2/event.hxx b/include/sfx2/event.hxx
index 021472830ab8..1024dd5b2423 100644
--- a/include/sfx2/event.hxx
+++ b/include/sfx2/event.hxx
@@ -196,11 +196,13 @@ class SFX2_DLLPUBLIC SfxEventHint : public SfxHint
     SfxEventHintId      nEventId;
 
 public:
-    SfxEventHint( SfxEventHintId nId, OUString aName, SfxObjectShell *pObj )
-                        :   pObjShell(pObj),
-                            aEventName(std::move(aName)),
-                            nEventId(nId)
-                        {}
+    SfxEventHint(SfxEventHintId nId, OUString aName, SfxObjectShell *pObj)
+        : SfxHint(SfxHintId::ThisIsAnSfxEventHint)
+        , pObjShell(pObj)
+        , aEventName(std::move(aName))
+        , nEventId(nId)
+    {
+    }
 
     SfxEventHintId      GetEventId() const
                         { return nEventId; }
diff --git a/include/svl/hint.hxx b/include/svl/hint.hxx
index e0807ca89cae..5a0698664350 100644
--- a/include/svl/hint.hxx
+++ b/include/svl/hint.hxx
@@ -145,7 +145,8 @@ enum class SfxHintId {
     SwDeleteChar,
     SwSectionHidden,
 
-    ThisIsAnSdrHint
+    ThisIsAnSdrHint,
+    ThisIsAnSfxEventHint
 };
 
 template< typename charT, typename traits >
diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx
index 1afa94c23822..5667766b827f 100644
--- a/sc/source/ui/app/inputwin.cxx
+++ b/sc/source/ui/app/inputwin.cxx
@@ -2406,16 +2406,16 @@ void ScPosWnd::Notify( SfxBroadcaster&, const SfxHint& 
rHint )
     if ( bFormulaMode )
         return;
 
+    const SfxHintId nHintId = rHint.GetId();
     // Does the list of range names need updating?
-    if ( auto pEventHint = dynamic_cast<const SfxEventHint*>(&rHint) )
+    if (nHintId == SfxHintId::ThisIsAnSfxEventHint)
     {
-        SfxEventHintId nEventId = pEventHint->GetEventId();
+        SfxEventHintId nEventId = static_cast<const 
SfxEventHint&>(rHint).GetEventId();
         if ( nEventId == SfxEventHintId::ActivateDoc )
             FillRangeNames();
     }
     else
     {
-        const SfxHintId nHintId = rHint.GetId();
         if (nHintId == SfxHintId::ScAreasChanged || nHintId == 
SfxHintId::ScNavigatorUpdateAll)
             FillRangeNames();
     }
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index d682e4854233..41035532cb27 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -708,11 +708,9 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& 
rHint )
             m_pAutoStyleList.reset( new ScAutoStyleList(this) );
         m_pAutoStyleList->AddInitial( aRange, aName1, nTimeout, aName2 );
     }
-    else if ( auto pEventHint = dynamic_cast<const SfxEventHint*>(&rHint) )
+    else if (rHint.GetId() == SfxHintId::ThisIsAnSfxEventHint)
     {
-        SfxEventHintId nEventId = pEventHint->GetEventId();
-
-        switch ( nEventId )
+        switch (static_cast<const SfxEventHint&>(rHint).GetEventId())
         {
             case SfxEventHintId::LoadFinished:
                 {
@@ -1082,11 +1080,10 @@ void ScDocShell::Notify( SfxBroadcaster&, const 
SfxHint& rHint )
         }
     }
 
-    const SfxEventHint* pSfxEventHint = dynamic_cast<const 
SfxEventHint*>(&rHint);
-    if (!pSfxEventHint)
+    if (rHint.GetId() != SfxHintId::ThisIsAnSfxEventHint)
         return;
 
-    switch( pSfxEventHint->GetEventId() )
+    switch(static_cast<const SfxEventHint&>(rHint).GetEventId())
     {
        case SfxEventHintId::CreateDoc:
             {
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx 
b/sc/source/ui/docshell/externalrefmgr.cxx
index 933cc1ad5b11..0653d4609aee 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -3284,12 +3284,10 @@ void 
ScExternalRefManager::transformUnsavedRefToSavedRef( SfxObjectShell* pShell
 
 void ScExternalRefManager::Notify( SfxBroadcaster&, const SfxHint& rHint )
 {
-    const SfxEventHint* pEventHint = dynamic_cast<const SfxEventHint*>(&rHint);
-    if ( !pEventHint )
+    if (rHint.GetId() != SfxHintId::ThisIsAnSfxEventHint)
         return;
 
-    SfxEventHintId nEventId = pEventHint->GetEventId();
-    switch ( nEventId )
+    switch (static_cast<const SfxEventHint&>(rHint).GetEventId())
     {
         case SfxEventHintId::PrepareCloseDoc:
             {
diff --git a/sc/source/ui/navipi/navipi.cxx b/sc/source/ui/navipi/navipi.cxx
index 1934b14ca374..037bc9b0836c 100644
--- a/sc/source/ui/navipi/navipi.cxx
+++ b/sc/source/ui/navipi/navipi.cxx
@@ -488,9 +488,10 @@ ScNavigatorDlg::~ScNavigatorDlg()
 
 void ScNavigatorDlg::Notify( SfxBroadcaster&, const SfxHint& rHint )
 {
-    if (const SfxEventHint* pHint = dynamic_cast<const SfxEventHint*>(&rHint))
+    if (rHint.GetId() == SfxHintId::ThisIsAnSfxEventHint)
     {
-        if (pHint->GetEventId() == SfxEventHintId::ActivateDoc)
+        const SfxEventHint& rEventHint = static_cast<const 
SfxEventHint&>(rHint);
+        if (rEventHint.GetEventId() == SfxEventHintId::ActivateDoc)
         {
             UpdateSheetLimits();
             bool bRefreshed = m_xLbEntries->ActiveDocChanged();
diff --git a/sd/source/ui/view/ViewShellBase.cxx 
b/sd/source/ui/view/ViewShellBase.cxx
index 19be45aaca12..0f9123f5c374 100644
--- a/sd/source/ui/view/ViewShellBase.cxx
+++ b/sd/source/ui/view/ViewShellBase.cxx
@@ -401,10 +401,11 @@ void ViewShellBase::Notify(SfxBroadcaster& rBC, const 
SfxHint& rHint)
 {
     SfxViewShell::Notify(rBC, rHint);
 
-    const SfxEventHint* pEventHint = dynamic_cast<const SfxEventHint*>(&rHint);
-    if (pEventHint)
+    const SfxHintId nHintId = rHint.GetId();
+
+    if (nHintId == SfxHintId::ThisIsAnSfxEventHint)
     {
-        switch (pEventHint->GetEventId())
+        switch (static_cast<const SfxEventHint&>(rHint).GetEventId())
         {
             case SfxEventHintId::OpenDoc:
                 if( GetDocument() && GetDocument()->IsStartWithPresentation() )
@@ -423,8 +424,7 @@ void ViewShellBase::Notify(SfxBroadcaster& rBC, const 
SfxHint& rHint)
     }
     else
     {
-        const SfxHintId nSlot = rHint.GetId();
-        switch ( nSlot )
+        switch (nHintId)
         {
             case SfxHintId::LanguageChanged:
             {
diff --git a/sfx2/source/appl/sfxpicklist.cxx b/sfx2/source/appl/sfxpicklist.cxx
index fb676d981d35..54288d959afa 100644
--- a/sfx2/source/appl/sfxpicklist.cxx
+++ b/sfx2/source/appl/sfxpicklist.cxx
@@ -161,16 +161,16 @@ void SfxPickListImpl::Notify( SfxBroadcaster&, const 
SfxHint& rHint )
         INetURLHistory::GetOrCreate()->PutUrl( INetURLObject( 
pOpenUrlHint->GetDocumentURL() ));
     }
 
-    const SfxEventHint* pEventHint = dynamic_cast<const SfxEventHint*>(&rHint);
-    if ( !pEventHint )
+    if (rHint.GetId() != SfxHintId::ThisIsAnSfxEventHint)
         return;
 
+    const SfxEventHint& rEventHint = static_cast<const SfxEventHint&>(rHint);
     // only ObjectShell-related events with media interest
-    SfxObjectShell* pDocSh = pEventHint->GetObjShell();
+    SfxObjectShell* pDocSh = rEventHint.GetObjShell();
     if( !pDocSh )
         return;
 
-    switch ( pEventHint->GetEventId() )
+    switch (rEventHint.GetEventId())
     {
         case SfxEventHintId::CreateDoc:
         {
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx
index 30454ce31d3b..85bef309f79a 100644
--- a/sfx2/source/doc/sfxbasemodel.cxx
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -2848,12 +2848,10 @@ void SfxBaseModel::Notify(          SfxBroadcaster& rBC 
    ,
 
     if ( rHint.GetId() == SfxHintId::DocChanged )
         changing();
-
-    const SfxEventHint* pNamedHint = dynamic_cast<const SfxEventHint*>(&rHint);
-    if ( pNamedHint )
+    else if (rHint.GetId() == SfxHintId::ThisIsAnSfxEventHint)
     {
-
-        switch ( pNamedHint->GetEventId() )
+        const SfxEventHint& rNamedHint = static_cast<const 
SfxEventHint&>(rHint);
+        switch (rNamedHint.GetEventId())
         {
         case SfxEventHintId::StorageChanged:
         {
@@ -2921,10 +2919,9 @@ void SfxBaseModel::Notify(          SfxBroadcaster& rBC  
   ,
         if (const SfxPrintingHint* pPrintingHint = dynamic_cast<const 
SfxPrintingHint*>(&rHint))
             aSupplement <<= pPrintingHint->GetWhich();
         const SfxViewEventHint* pViewHint = dynamic_cast<const 
SfxViewEventHint*>(&rHint);
-        postEvent_Impl( pNamedHint->GetEventName(), pViewHint ? 
pViewHint->GetController() : Reference< frame::XController2 >(), aSupplement );
+        postEvent_Impl( rNamedHint.GetEventName(), pViewHint ? 
pViewHint->GetController() : Reference< frame::XController2 >(), aSupplement );
     }
-
-    if ( rHint.GetId() == SfxHintId::TitleChanged )
+    else if ( rHint.GetId() == SfxHintId::TitleChanged )
     {
         addTitle_Impl( m_pData->m_seqArguments, 
m_pData->m_pObjectShell->GetTitle() );
         postEvent_Impl( GlobalEventConfig::GetEventName( 
GlobalEventId::TITLECHANGED ) );
diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
index 39fb14962008..9703851e7beb 100644
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -1405,12 +1405,12 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, 
const SfxHint& rHint )
         return;
 
     // we know only SfxEventHint or simple SfxHint
-    if (const SfxEventHint* pEventHint = dynamic_cast<const 
SfxEventHint*>(&rHint))
+    if (rHint.GetId() == SfxHintId::ThisIsAnSfxEventHint)
     {
         // When the Document is loaded asynchronously, was the Dispatcher
         // set as ReadOnly, to what must be returned when the document itself
         // is not read only, and the loading is finished.
-        switch ( pEventHint->GetEventId() )
+        switch (static_cast<const SfxEventHint&>(rHint).GetEventId())
         {
             case SfxEventHintId::ModifyChanged:
             {
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 5c8d2bc6cf65..8ad4fe841c88 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -2614,9 +2614,11 @@ SfxViewShell* SfxViewShell::GetNext
 void SfxViewShell::Notify( SfxBroadcaster& rBC,
                             const SfxHint& rHint )
 {
-    const SfxEventHint* pEventHint = dynamic_cast<const SfxEventHint*>(&rHint);
-    if ( !(pEventHint && pEventHint->GetEventId() == 
SfxEventHintId::LoadFinished) )
+    if (rHint.GetId() != SfxHintId::ThisIsAnSfxEventHint ||
+        static_cast<const SfxEventHint&>(rHint).GetEventId() != 
SfxEventHintId::LoadFinished)
+    {
         return;
+    }
 
     if ( !GetController().is() )
         return;
diff --git a/svx/source/form/fmundo.cxx b/svx/source/form/fmundo.cxx
index 9f627a7358b4..facf627a7b1c 100644
--- a/svx/source/form/fmundo.cxx
+++ b/svx/source/form/fmundo.cxx
@@ -321,9 +321,9 @@ void FmXUndoEnvironment::Notify( SfxBroadcaster& /*rBC*/, 
const SfxHint& rHint )
             default: break;
         }
     }
-    else if (const SfxEventHint* pEventHint = dynamic_cast<const 
SfxEventHint*>(&rHint))
+    else if (rHint.GetId() == SfxHintId::ThisIsAnSfxEventHint)
     {
-        switch (pEventHint->GetEventId())
+        switch (static_cast<const SfxEventHint&>(rHint).GetEventId())
         {
             case SfxEventHintId::CreateDoc:
             case SfxEventHintId::OpenDoc:
diff --git a/sw/source/uibase/app/apphdl.cxx b/sw/source/uibase/app/apphdl.cxx
index d7a452f5cc50..030a5b73c14e 100644
--- a/sw/source/uibase/app/apphdl.cxx
+++ b/sw/source/uibase/app/apphdl.cxx
@@ -868,13 +868,14 @@ void SwModule::ExecOther(SfxRequest& rReq)
 // Catch hint for DocInfo
 void SwModule::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
 {
-    if( const SfxEventHint* pEvHint = dynamic_cast<const SfxEventHint*>( 
&rHint) )
+    if (rHint.GetId() == SfxHintId::ThisIsAnSfxEventHint)
     {
-        SwDocShell* pDocSh = dynamic_cast<SwDocShell*>( pEvHint->GetObjShell() 
 );
+        const SfxEventHint& rEvHint = static_cast<const SfxEventHint&>(rHint);
+        SwDocShell* pDocSh = dynamic_cast<SwDocShell*>(rEvHint.GetObjShell());
         if( pDocSh )
         {
             SwWrtShell* pWrtSh = pDocSh->GetWrtShell();
-            switch( pEvHint->GetEventId() )
+            switch (rEvHint.GetEventId())
             {
             case SfxEventHintId::LoadFinished:
                 // if it is a new document created from a template,
diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx
index d8195b7e200d..94aa78c5aa5f 100644
--- a/sw/source/uibase/app/docsh2.cxx
+++ b/sw/source/uibase/app/docsh2.cxx
@@ -213,12 +213,11 @@ void SwDocShell::DoFlushDocInfo()
 static void lcl_processCompatibleSfxHint( const uno::Reference< 
script::vba::XVBAEventProcessor >& xVbaEvents, const SfxHint& rHint )
 {
     using namespace com::sun::star::script::vba::VBAEventId;
-    const SfxEventHint* pSfxEventHint = dynamic_cast<const 
SfxEventHint*>(&rHint);
-    if ( !pSfxEventHint )
+    if (rHint.GetId() != SfxHintId::ThisIsAnSfxEventHint)
         return;
 
     uno::Sequence< uno::Any > aArgs;
-    switch( pSfxEventHint->GetEventId() )
+    switch (static_cast<const SfxEventHint&>(rHint).GetEventId())
     {
         case SfxEventHintId::CreateDoc:
             xVbaEvents->processVbaEvent(AUTO_NEW, aArgs);
@@ -245,9 +244,9 @@ void SwDocShell::Notify( SfxBroadcaster&, const SfxHint& 
rHint )
     if( xVbaEvents.is() )
         lcl_processCompatibleSfxHint( xVbaEvents, rHint );
 
-    if ( const SfxEventHint* pSfxEventHint = dynamic_cast<const 
SfxEventHint*>(&rHint) )
+    if (rHint.GetId() == SfxHintId::ThisIsAnSfxEventHint)
     {
-        switch( pSfxEventHint->GetEventId() )
+        switch (static_cast<const SfxEventHint&>(rHint).GetEventId())
         {
             case SfxEventHintId::ActivateDoc:
             case SfxEventHintId::CreateDoc:
@@ -261,7 +260,7 @@ void SwDocShell::Notify( SfxBroadcaster&, const SfxHint& 
rHint )
                 break;
         }
 
-        switch( pSfxEventHint->GetEventId() )
+        switch (static_cast<const SfxEventHint&>(rHint).GetEventId())
         {
             case SfxEventHintId::CreateDoc:
                 {
@@ -285,8 +284,8 @@ void SwDocShell::Notify( SfxBroadcaster&, const SfxHint& 
rHint )
     }
 
     sal_uInt16 nAction = 0;
-    auto pEventHint = dynamic_cast<const SfxEventHint*>(&rHint);
-    if( pEventHint && pEventHint->GetEventId() == SfxEventHintId::LoadFinished 
)
+    if (rHint.GetId() == SfxHintId::ThisIsAnSfxEventHint &&
+        static_cast<const SfxEventHint&>(rHint).GetEventId() == 
SfxEventHintId::LoadFinished)
     {
         // #i38126# - own action id
         nAction = 3;
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx 
b/sw/source/uibase/docvw/PostItMgr.cxx
index a0fda9fd7caa..10f866e5c9bb 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -339,9 +339,10 @@ void SwPostItMgr::RemoveItem( SfxBroadcaster* pBroadcast )
 
 void SwPostItMgr::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
 {
-    if ( const SfxEventHint* pSfxEventHint = dynamic_cast<const 
SfxEventHint*>(&rHint) )
+    if (rHint.GetId() == SfxHintId::ThisIsAnSfxEventHint)
     {
-        if ( pSfxEventHint->GetEventId() == 
SfxEventHintId::SwEventLayoutFinished )
+        const SfxEventHint& rSfxEventHint = static_cast<const 
SfxEventHint&>(rHint);
+        if (rSfxEventHint.GetEventId() == 
SfxEventHintId::SwEventLayoutFinished)
         {
             if ( !mbWaitingForCalcRects && !mvPostItFields.empty())
             {
diff --git a/sw/source/uibase/uno/unoatxt.cxx b/sw/source/uibase/uno/unoatxt.cxx
index 5e037b4d679a..f601388c5dc8 100644
--- a/sw/source/uibase/uno/unoatxt.cxx
+++ b/sw/source/uibase/uno/unoatxt.cxx
@@ -707,9 +707,10 @@ void SwXAutoTextEntry::Notify( SfxBroadcaster& _rBC, const 
SfxHint& _rHint )
         return;
 
 // it's our document
-    if (const SfxEventHint* pEventHint = dynamic_cast<const 
SfxEventHint*>(&_rHint))
+    if (_rHint.GetId() == SfxHintId::ThisIsAnSfxEventHint)
     {
-        if (SfxEventHintId::PrepareCloseDoc == pEventHint->GetEventId())
+        const SfxEventHint& rEventHint = static_cast<const 
SfxEventHint&>(_rHint);
+        if (SfxEventHintId::PrepareCloseDoc == rEventHint.GetEventId())
         {
             implFlushDocument();
             mxBodyText.clear();
diff --git a/sw/source/uibase/utlui/navipi.cxx 
b/sw/source/uibase/utlui/navipi.cxx
index bd53813ac64b..a54ccda3ab63 100644
--- a/sw/source/uibase/utlui/navipi.cxx
+++ b/sw/source/uibase/utlui/navipi.cxx
@@ -845,9 +845,9 @@ void SwNavigationPI::Notify( SfxBroadcaster& rBrdc, const 
SfxHint& rHint )
     }
     else
     {
-        if (const SfxEventHint* pHint = dynamic_cast<const 
SfxEventHint*>(&rHint))
+        if (rHint.GetId() == SfxHintId::ThisIsAnSfxEventHint)
         {
-            SfxEventHintId eEventId = pHint->GetEventId();
+            SfxEventHintId eEventId = static_cast<const 
SfxEventHint&>(rHint).GetEventId();
             if (eEventId == SfxEventHintId::OpenDoc)
             {
                 SwView *pActView = GetCreateView();

Reply via email to