include/svx/svdobj.hxx          |    2 +-
 svx/source/svdraw/svdedxv.cxx   |    6 +++++-
 svx/source/svdraw/svdobj.cxx    |    2 +-
 svx/source/svdraw/svdoedge.cxx  |    4 ++--
 svx/source/unodraw/unoshtxt.cxx |   12 +++++-------
 5 files changed, 14 insertions(+), 12 deletions(-)

New commits:
commit 4d0ba0badeb5a83d8eb5373ba5d7ef931dcf62c9
Author:     Noel Grandin <[email protected]>
AuthorDate: Wed Jun 26 11:18:47 2024 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Wed Jun 26 18:53:12 2024 +0200

    reduce number of SvxTextEditSourceImpl listeners on SdrModel
    
    when we have a lot of shapes, the number of listeners attached to
    SdrModel becomes a serious bottleneck because of the number of
    broadcast/notify function calls.
    
    But SvxTextEditSourceImpl can just as well listen to the SdrObject,
    which achieves the same end, and reduces the bottleneck on the SdrModel.
    
    We do have to adjust some of the broadcast sites to broadcast the
    event to the SdrObject listeners as well as the SdrModel listeners.
    Possibly as another change we can remove the broadcasting to the
    SdrModel listeners.
    
    This shaves 10% off the load time of a large DOCX with lots of shapes.
    
    Noting that we do no need to listen to SdrHintKind::ModelCleared because
    we will get called via SvxTextEditSourceImpl::ObjectInDestruction when
    the model is destroyed.
    
    Change-Id: I3f7f6aa2a2146e4c4f59c974aa3fed92becf5eca
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169565
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/include/svx/svdobj.hxx b/include/svx/svdobj.hxx
index 8dd17bdc00f5..f1bee52e87ec 100644
--- a/include/svx/svdobj.hxx
+++ b/include/svx/svdobj.hxx
@@ -409,7 +409,7 @@ public:
 
     void BroadcastObjectChange() const;
 
-    const SfxBroadcaster* GetBroadcaster() const;
+    SfxBroadcaster* GetBroadcaster() const;
 
     // set modified-flag in the model
     virtual void SetChanged();
diff --git a/svx/source/svdraw/svdedxv.cxx b/svx/source/svdraw/svdedxv.cxx
index 6071fbc042bd..fe647da817a1 100644
--- a/svx/source/svdraw/svdedxv.cxx
+++ b/svx/source/svdraw/svdedxv.cxx
@@ -1577,6 +1577,8 @@ bool SdrObjEditView::SdrBeginTextEdit(SdrObject* pObj_, 
SdrPageView* pPV, vcl::W
 
             SdrHint aHint(SdrHintKind::BeginEdit, *pTextObj);
             GetModel().Broadcast(aHint);
+            if (auto pBroadcaster = pTextObj->GetBroadcaster())
+                pBroadcaster->Broadcast(aHint);
 
             mpTextEditOutliner->setVisualizedPage(nullptr);
 
@@ -1715,6 +1717,8 @@ SdrEndTextEditKind SdrObjEditView::SdrEndTextEdit(bool 
bDontDeleteReally)
     {
         SdrHint aHint(SdrHintKind::EndEdit, *pTextEditObj);
         GetModel().Broadcast(aHint);
+        if (auto pBroadcaster = pTextEditObj->GetBroadcaster())
+            pBroadcaster->Broadcast(aHint);
     }
 
     // if new mechanism was used, clean it up. At cleanup no need to check
@@ -1895,7 +1899,7 @@ SdrEndTextEditKind SdrObjEditView::SdrEndTextEdit(bool 
bDontDeleteReally)
     if (pTEObj && !pTEObj->getSdrModelFromSdrObject().isLocked() && 
pTEObj->GetBroadcaster())
     {
         SdrHint aHint(SdrHintKind::EndEdit, *pTEObj);
-        
const_cast<SfxBroadcaster*>(pTEObj->GetBroadcaster())->Broadcast(aHint);
+        pTEObj->GetBroadcaster()->Broadcast(aHint);
     }
 
     if (pUndoEditUndoManager)
diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx
index a598517d6893..6c8330185f0a 100644
--- a/svx/source/svdraw/svdobj.cxx
+++ b/svx/source/svdraw/svdobj.cxx
@@ -684,7 +684,7 @@ void SdrObject::RemoveListener(SfxListener& rListener)
     }
 }
 
-const SfxBroadcaster* SdrObject::GetBroadcaster() const
+SfxBroadcaster* SdrObject::GetBroadcaster() const
 {
     return m_pPlusData!=nullptr ? m_pPlusData->pBroadcast.get() : nullptr;
 }
diff --git a/svx/source/svdraw/svdoedge.cxx b/svx/source/svdraw/svdoedge.cxx
index 948b39a1d3b5..b37385a93c73 100644
--- a/svx/source/svdraw/svdoedge.cxx
+++ b/svx/source/svdraw/svdoedge.cxx
@@ -1708,13 +1708,13 @@ void SdrEdgeObj::Reformat()
     if( nullptr != m_aCon1.m_pSdrObj )
     {
         SfxHint aHint( SfxHintId::DataChanged );
-        Notify( 
*const_cast<SfxBroadcaster*>(m_aCon1.m_pSdrObj->GetBroadcaster()), aHint );
+        Notify( *m_aCon1.m_pSdrObj->GetBroadcaster(), aHint );
     }
 
     if( nullptr != m_aCon2.m_pSdrObj )
     {
         SfxHint aHint( SfxHintId::DataChanged );
-        Notify( 
*const_cast<SfxBroadcaster*>(m_aCon2.m_pSdrObj->GetBroadcaster()), aHint );
+        Notify( *m_aCon2.m_pSdrObj->GetBroadcaster(), aHint );
     }
 }
 
diff --git a/svx/source/unodraw/unoshtxt.cxx b/svx/source/unodraw/unoshtxt.cxx
index 37314e6f1bb6..33c5a5dc0c29 100644
--- a/svx/source/unodraw/unoshtxt.cxx
+++ b/svx/source/unodraw/unoshtxt.cxx
@@ -175,11 +175,11 @@ SvxTextEditSourceImpl::SvxTextEditSourceImpl( SdrObject* 
pObject, SdrText* pText
             mpText = pTextObj->getText( 0 );
     }
 
-    if( mpModel )
-        StartListening( *mpModel );
-
     if( mpObject )
+    {
+        mpObject->AddListener( *this );
         mpObject->AddObjectUser( *this );
+    }
 }
 
 
@@ -206,7 +206,7 @@ SvxTextEditSourceImpl::SvxTextEditSourceImpl( SdrObject& 
rObject, SdrText* pText
             mpText = pTextObj->getText( 0 );
     }
 
-    StartListening( *mpModel );
+    rObject.AddListener( *this );
     StartListening( *mpView );
     mpObject->AddObjectUser( *this );
 
@@ -366,9 +366,6 @@ void SvxTextEditSourceImpl::Notify(SfxBroadcaster& rBC, 
const SfxHint& rHint)
                 }
                 break;
 
-            case SdrHintKind::ModelCleared:
-                dispose();
-                break;
             default:
                 break;
         }
@@ -426,6 +423,7 @@ void SvxTextEditSourceImpl::dispose()
 
     if( mpObject )
     {
+        mpObject->RemoveListener( *this );
         mpObject->RemoveObjectUser( *this );
         mpObject = nullptr;
     }

Reply via email to