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

Miklos Vajna vmiklos at collabora.co.uk
Fri Jul 29 11:39:56 UTC 2016


 compilerplugins/clang/badstatics.cxx |    3 ---
 include/sfx2/viewsh.hxx              |    1 +
 sfx2/source/view/lokhelper.cxx       |   29 ++++++-----------------------
 sfx2/source/view/viewimp.hxx         |    2 ++
 sfx2/source/view/viewsh.cxx          |    9 +++++++++
 5 files changed, 18 insertions(+), 26 deletions(-)

New commits:
commit 389d4d414291879b9097658080e405a06dc0c1fc
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Jul 29 11:47:22 2016 +0200

    sfx2: introduce SfxViewShell::GetViewShellId()
    
    This is quite similar to SwFrame::GetFrameId(), i.e. it assigns a
    numeric identifier to each instance to help debugging, as those
    identifiers are stable accross runs.
    
    Change-Id: I9cc57e316435f0284a1d481a956a703be859d67e
    Reviewed-on: https://gerrit.libreoffice.org/27669
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/compilerplugins/clang/badstatics.cxx b/compilerplugins/clang/badstatics.cxx
index 7f09dbc..12e6b93 100644
--- a/compilerplugins/clang/badstatics.cxx
+++ b/compilerplugins/clang/badstatics.cxx
@@ -150,9 +150,6 @@ public:
                     // ScAddInAsync* keys if that set is not empty at exit
                 || name == "g_aWindowList"
                     //vcl/unx/gtk/a11y/atkutil.cxx, asserted empty at exit
-                || name=="aViewMap"
-                    // sfx2/source/view/lokhelper.cxx, not owning, leaked by
-                    // (mis-)design
                ) // these variables appear unproblematic
             {
                 return true;
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index a665913..f6e5777 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -334,6 +334,7 @@ public:
     /// See lok::Document::getPart().
     virtual int getPart() const;
     virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const;
+    sal_uInt32 GetViewShellId() const;
 };
 
 
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 09d78cf..856a007 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -17,42 +17,24 @@
 
 #include <shellimpl.hxx>
 
-namespace
-{
-
-/// Assigns a view ID to a view shell.
-int shellToView(SfxViewShell* pViewShell)
-{
-    // Deleted view shells are not removed from this map, so view IDs are not
-    // reused when deleting, then creating a view.
-    static std::map<SfxViewShell*, int> aViewMap;
-    auto it = aViewMap.find(pViewShell);
-    if (it != aViewMap.end())
-        return it->second;
-
-    int nViewId = aViewMap.size();
-    aViewMap[pViewShell] = nViewId;
-    return nViewId;
-}
-}
-
 int SfxLokHelper::createView()
 {
     SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst();
     SfxRequest aRequest(pViewFrame, SID_NEWWINDOW);
     pViewFrame->ExecView_Impl(aRequest);
 
-    return shellToView(SfxViewShell::Current());
+    return SfxViewShell::Current()->GetViewShellId();
 }
 
 void SfxLokHelper::destroyView(int nId)
 {
+    unsigned nViewShellId = nId;
     SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
 
     for (std::size_t i = 0; i < rViewArr.size(); ++i)
     {
         SfxViewShell* pViewShell = rViewArr[i];
-        if (shellToView(pViewShell) == nId)
+        if (pViewShell->GetViewShellId() == nViewShellId)
         {
             SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
             SfxRequest aRequest(pViewFrame, SID_CLOSEWIN);
@@ -64,12 +46,13 @@ void SfxLokHelper::destroyView(int nId)
 
 void SfxLokHelper::setView(int nId)
 {
+    unsigned nViewShellId = nId;
     SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
 
     for (std::size_t i = 0; i < rViewArr.size(); ++i)
     {
         SfxViewShell* pViewShell = rViewArr[i];
-        if (shellToView(pViewShell) == nId)
+        if (pViewShell->GetViewShellId() == nViewShellId)
         {
             if (pViewShell == SfxViewShell::Current())
                 return;
@@ -86,7 +69,7 @@ int SfxLokHelper::getView(SfxViewShell* pViewShell)
 {
     if (!pViewShell)
         pViewShell = SfxViewShell::Current();
-    return shellToView(pViewShell);
+    return pViewShell->GetViewShellId();
 }
 
 std::size_t SfxLokHelper::getViews()
diff --git a/sfx2/source/view/viewimp.hxx b/sfx2/source/view/viewimp.hxx
index fa3e680..95fdf82 100644
--- a/sfx2/source/view/viewimp.hxx
+++ b/sfx2/source/view/viewimp.hxx
@@ -62,6 +62,8 @@ struct SfxViewShell_Impl
     void* m_pLibreOfficeKitViewData;
     /// Set if we are in the middle of a tiled search.
     bool m_bTiledSearching;
+    static sal_uInt32 m_nLastViewShellId;
+    const sal_uInt32 m_nViewShellId;
 
     explicit SfxViewShell_Impl(SfxViewShellFlags const nFlags);
     ~SfxViewShell_Impl();
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 2108633..6ffd253 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -238,6 +238,8 @@ public:
     size_t size() const { return maData.size(); }
 };
 
+sal_uInt32 SfxViewShell_Impl::m_nLastViewShellId = 0;
+
 SfxViewShell_Impl::SfxViewShell_Impl(SfxViewShellFlags const nFlags)
 : aInterceptorContainer( aMutex )
 ,   m_bControllerSet(false)
@@ -252,6 +254,7 @@ SfxViewShell_Impl::SfxViewShell_Impl(SfxViewShellFlags const nFlags)
 ,   m_pLibreOfficeKitViewCallback(nullptr)
 ,   m_pLibreOfficeKitViewData(nullptr)
 ,   m_bTiledSearching(false)
+,   m_nViewShellId(SfxViewShell_Impl::m_nLastViewShellId++)
 {}
 
 SfxViewShell_Impl::~SfxViewShell_Impl()
@@ -1502,10 +1505,16 @@ int SfxViewShell::getPart() const
     return 0;
 }
 
+sal_uInt32 SfxViewShell::GetViewShellId() const
+{
+    return pImpl->m_nViewShellId;
+}
+
 void SfxViewShell::dumpAsXml(xmlTextWriterPtr pWriter) const
 {
     xmlTextWriterStartElement(pWriter, BAD_CAST("sfxViewShell"));
     xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
+    xmlTextWriterWriteAttribute(pWriter, BAD_CAST("id"), BAD_CAST(OString::number(GetViewShellId()).getStr()));
     xmlTextWriterEndElement(pWriter);
 }
 


More information about the Libreoffice-commits mailing list