[Libreoffice-commits] core.git: include/sfx2 sfx2/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Sep 13 07:57:27 UTC 2018


 include/sfx2/dispatch.hxx        |    2 +-
 include/sfx2/hintpost.hxx        |   10 ++++++----
 sfx2/source/control/dispatch.cxx |   18 +++++++-----------
 sfx2/source/notify/hintpost.cxx  |   12 +++++++-----
 4 files changed, 21 insertions(+), 21 deletions(-)

New commits:
commit cbfb7f463cbf39ec59b5a4e4f9bb07e89f8c9d13
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Sep 12 16:36:29 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Sep 13 09:56:59 2018 +0200

    pass SfxRequest around by std::unique_ptr
    
    - remove a couple of copies in the process
    - need to use std::function instead of LINK to handle the unique_ptr
    
    Change-Id: Ic760d2fc639bf2e11d5bddbfbb6f2d5f15b78fe3
    Reviewed-on: https://gerrit.libreoffice.org/60397
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/sfx2/dispatch.hxx b/include/sfx2/dispatch.hxx
index 3ff8856985a2..9d91d7f60966 100644
--- a/include/sfx2/dispatch.hxx
+++ b/include/sfx2/dispatch.hxx
@@ -95,7 +95,7 @@ friend class SfxPopupMenuManager;
 friend class SfxHelp;
 
     DECL_DLLPRIVATE_LINK( EventHdl_Impl, Timer *, void );
-    DECL_DLLPRIVATE_LINK( PostMsgHandler, SfxRequest *, void );
+    void PostMsgHandler(std::unique_ptr<SfxRequest>);
 
     SAL_DLLPRIVATE void Call_Impl( SfxShell& rShell, const SfxSlot &rSlot, SfxRequest &rReq, bool bRecord );
     SAL_DLLPRIVATE void Update_Impl_( bool,bool,bool,SfxWorkWindow*);
diff --git a/include/sfx2/hintpost.hxx b/include/sfx2/hintpost.hxx
index cfbc60d87631..ce5f5ac8f0e2 100644
--- a/include/sfx2/hintpost.hxx
+++ b/include/sfx2/hintpost.hxx
@@ -21,6 +21,8 @@
 
 #include <tools/link.hxx>
 #include <tools/ref.hxx>
+#include <functional>
+#include <memory>
 
 
 class SfxRequest;
@@ -39,7 +41,7 @@ class SfxRequest;
 class SfxHintPoster : public SvRefBase
 {
 private:
-    Link<SfxRequest*,void> m_Link;
+    std::function<void (std::unique_ptr<SfxRequest>)> m_Link;
 
                     DECL_LINK( DoEvent_Impl, void*, void );
 
@@ -47,10 +49,10 @@ protected:
     virtual         ~SfxHintPoster() override;
 
 public:
-                    SfxHintPoster(const Link<SfxRequest*,void>& rLink);
+                    SfxHintPoster(const std::function<void (std::unique_ptr<SfxRequest>)>& rLink);
 
-    void            Post( SfxRequest* pHint );
-    void            SetEventHdl(const Link<SfxRequest*,void>& rLink);
+    void            Post( std::unique_ptr<SfxRequest> pHint );
+    void            SetEventHdl(const std::function<void (std::unique_ptr<SfxRequest>)>& rLink);
 };
 
 #endif
diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx
index 2b39a7dfbef7..efe847cd4a1d 100644
--- a/sfx2/source/control/dispatch.cxx
+++ b/sfx2/source/control/dispatch.cxx
@@ -410,9 +410,7 @@ void SfxDispatcher::Construct_Impl()
     for (SfxObjectBars_Impl & rObjBar : xImp->aObjBars)
         rObjBar.eId = ToolbarId::None;
 
-    Link<SfxRequest*,void> aGenLink( LINK(this, SfxDispatcher, PostMsgHandler) );
-
-    xImp->xPoster = new SfxHintPoster(aGenLink);
+    xImp->xPoster = new SfxHintPoster(std::bind(&SfxDispatcher::PostMsgHandler, this, std::placeholders::_1));
 
     xImp->aIdle.SetPriority(TaskPriority::HIGH_IDLE );
     xImp->aIdle.SetInvokeHandler( LINK(this, SfxDispatcher, EventHdl_Impl ) );
@@ -445,7 +443,7 @@ SfxDispatcher::~SfxDispatcher()
 
     // So that no timer by Reschedule in PlugComm strikes the LeaveRegistrations
     xImp->aIdle.Stop();
-    xImp->xPoster->SetEventHdl( Link<SfxRequest*,void>() );
+    xImp->xPoster->SetEventHdl( std::function<void (std::unique_ptr<SfxRequest>)>() );
 
     // Notify the stack variables in Call_Impl
     if ( xImp->pInCallAliveFlag )
@@ -866,7 +864,7 @@ void SfxDispatcher::Execute_(SfxShell& rShell, const SfxSlot& rSlot,
                 {
                     if ( bool(eCallMode & SfxCallMode::RECORD) )
                         rReq.AllowRecording( true );
-                    pDispat->xImp->xPoster->Post(new SfxRequest(rReq));
+                    pDispat->xImp->xPoster->Post(o3tl::make_unique<SfxRequest>(rReq));
                     return;
                 }
             }
@@ -1104,7 +1102,7 @@ const SfxPoolItem* SfxDispatcher::ExecuteList(sal_uInt16 nSlot, SfxCallMode eCal
 
 /** Helper method to receive the asynchronously executed <SfxRequest>s.
 */
-IMPL_LINK(SfxDispatcher, PostMsgHandler, SfxRequest*, pReq, void)
+void SfxDispatcher::PostMsgHandler(std::unique_ptr<SfxRequest> pReq)
 {
     DBG_ASSERT( !xImp->bFlushing, "recursive call to dispatcher" );
     SFX_STACK(SfxDispatcher::PostMsgHandler);
@@ -1130,13 +1128,11 @@ IMPL_LINK(SfxDispatcher, PostMsgHandler, SfxRequest*, pReq, void)
         else
         {
             if ( xImp->bLocked )
-                xImp->aReqArr.emplace_back(new SfxRequest(*pReq));
+                xImp->aReqArr.emplace_back(std::move(pReq));
             else
-                xImp->xPoster->Post(new SfxRequest(*pReq));
+                xImp->xPoster->Post(std::move(pReq));
         }
     }
-
-    delete pReq;
 }
 
 void SfxDispatcher::SetMenu_Impl()
@@ -1957,7 +1953,7 @@ void SfxDispatcher::Lock( bool bLock )
     if ( !bLock )
     {
         for(size_t i = 0; i < xImp->aReqArr.size(); ++i)
-            xImp->xPoster->Post(xImp->aReqArr[i].release());
+            xImp->xPoster->Post(std::move(xImp->aReqArr[i]));
         xImp->aReqArr.clear();
     }
 }
diff --git a/sfx2/source/notify/hintpost.cxx b/sfx2/source/notify/hintpost.cxx
index cd7d0653b5fa..128573280cd3 100644
--- a/sfx2/source/notify/hintpost.cxx
+++ b/sfx2/source/notify/hintpost.cxx
@@ -21,10 +21,11 @@
 
 #include <arrdecl.hxx>
 #include <sfx2/app.hxx>
+#include <sfx2/request.hxx>
 #include <sfxtypes.hxx>
 
 
-SfxHintPoster::SfxHintPoster(const Link<SfxRequest*,void>& rLink)
+SfxHintPoster::SfxHintPoster(const std::function<void (std::unique_ptr<SfxRequest>)>& rLink)
     : m_Link(rLink)
 {
 }
@@ -33,19 +34,20 @@ SfxHintPoster::~SfxHintPoster()
 {
 }
 
-void SfxHintPoster::Post( SfxRequest* pHintToPost )
+void SfxHintPoster::Post( std::unique_ptr<SfxRequest> pHintToPost )
 {
-    Application::PostUserEvent( ( LINK(this, SfxHintPoster, DoEvent_Impl) ), pHintToPost );
+    Application::PostUserEvent( ( LINK(this, SfxHintPoster, DoEvent_Impl) ), pHintToPost.release() );
     AddFirstRef();
 }
 
 IMPL_LINK( SfxHintPoster, DoEvent_Impl, void *, pPostedHint, void )
 {
-    m_Link.Call( static_cast<SfxRequest*>(pPostedHint) );
+    if (m_Link)
+        m_Link( std::unique_ptr<SfxRequest>(static_cast<SfxRequest*>(pPostedHint)) );
     ReleaseRef();
 }
 
-void SfxHintPoster::SetEventHdl(const Link<SfxRequest*,void>& rLink)
+void SfxHintPoster::SetEventHdl(const std::function<void (std::unique_ptr<SfxRequest>)>& rLink)
 {
     m_Link = rLink;
 }


More information about the Libreoffice-commits mailing list