[Libreoffice-commits] core.git: 2 commits - sc/inc sc/source sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Jan 10 07:16:41 UTC 2019


 sc/inc/rangeutl.hxx               |    2 +-
 sc/source/core/tool/rangeutl.cxx  |   11 +++++------
 sc/source/ui/dbgui/consdlg.cxx    |   23 ++++++++---------------
 sw/source/core/bastyp/swcache.cxx |   23 +++++++++--------------
 sw/source/core/inc/swcache.hxx    |    6 +++---
 5 files changed, 26 insertions(+), 39 deletions(-)

New commits:
commit b8f497a06d585dbae3adadb4d177fe84fdb1b5fa
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Jan 9 12:52:54 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Jan 10 08:16:27 2019 +0100

    use unique_ptr in SwCache
    
    Change-Id: I2b961380dcb5eb26ce517f7b56e5c32f5e6429e4
    Reviewed-on: https://gerrit.libreoffice.org/66011
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/source/core/bastyp/swcache.cxx b/sw/source/core/bastyp/swcache.cxx
index 2693578c8b21..6abbbb51faea 100644
--- a/sw/source/core/bastyp/swcache.cxx
+++ b/sw/source/core/bastyp/swcache.cxx
@@ -125,9 +125,6 @@ SwCache::~SwCache()
             << "; number of Cache reductions: " << m_nDecreaseMax);
     Check();
 #endif
-
-    for(const auto& rpObj : m_aCacheObjects)
-        delete rpObj;
 }
 
 void SwCache::IncreaseMax( const sal_uInt16 nAdd )
@@ -163,8 +160,7 @@ void SwCache::Flush()
             pTmp = pObj;
             pObj = pTmp->GetNext();
             m_aFreePositions.push_back( pTmp->GetCachePos() );
-            m_aCacheObjects[pTmp->GetCachePos()] = nullptr;
-            delete pTmp;
+            m_aCacheObjects[pTmp->GetCachePos()].reset(); // deletes pTmp
             INCREMENT( m_nFlushedObjects );
         }
     }
@@ -236,7 +232,7 @@ SwCacheObj *SwCache::Get( const void *pOwner, const sal_uInt16 nIndex,
                           const bool bToTop )
 {
     SwCacheObj *pRet;
-    if ( nullptr != (pRet = (nIndex < m_aCacheObjects.size()) ? m_aCacheObjects[ nIndex ] : nullptr) )
+    if ( nullptr != (pRet = (nIndex < m_aCacheObjects.size()) ? m_aCacheObjects[ nIndex ].get() : nullptr) )
     {
         if ( !pRet->IsOwner( pOwner ) )
             pRet = nullptr;
@@ -300,8 +296,7 @@ void SwCache::DeleteObj( SwCacheObj *pObj )
         pObj->GetNext()->SetPrev( pObj->GetPrev() );
 
     m_aFreePositions.push_back( pObj->GetCachePos() );
-    m_aCacheObjects[pObj->GetCachePos()] = nullptr;
-    delete pObj;
+    m_aCacheObjects[pObj->GetCachePos()] = nullptr; // deletes pObj
 
     CHECK;
     if ( m_aCacheObjects.size() > m_nCurMax &&
@@ -312,9 +307,10 @@ void SwCache::DeleteObj( SwCacheObj *pObj )
         // these might not find them afterwards
         for ( size_t i = 0; i < m_aCacheObjects.size(); ++i )
         {
-            SwCacheObj *pTmpObj = m_aCacheObjects[i];
+            SwCacheObj *pTmpObj = m_aCacheObjects[i].get();
             if ( !pTmpObj )
-            {   m_aCacheObjects.erase( m_aCacheObjects.begin() + i );
+            {
+                m_aCacheObjects.erase( m_aCacheObjects.begin() + i );
                 --i;
             }
             else
@@ -346,7 +342,7 @@ bool SwCache::Insert( SwCacheObj *pNew )
         // there is still space; insert directly
         INCREMENT( m_nAppend );
         nPos = m_aCacheObjects.size();
-        m_aCacheObjects.push_back(pNew);
+        m_aCacheObjects.emplace_back(pNew);
     }
     else if ( !m_aFreePositions.empty() )
     {
@@ -354,7 +350,7 @@ bool SwCache::Insert( SwCacheObj *pNew )
         INCREMENT( m_nInsertFree );
         const sal_uInt16 nFreePos = m_aFreePositions.size() - 1;
         nPos = m_aFreePositions[ nFreePos ];
-        m_aCacheObjects[nPos] = pNew;
+        m_aCacheObjects[nPos].reset(pNew);
         m_aFreePositions.erase( m_aFreePositions.begin() + nFreePos );
     }
     else
@@ -403,8 +399,7 @@ bool SwCache::Insert( SwCacheObj *pNew )
         {
             pObj->GetNext()->SetPrev( pObj->GetPrev() );
         }
-        delete pObj;
-        m_aCacheObjects[nPos] = pNew;
+        m_aCacheObjects[nPos].reset(pNew);
     }
     pNew->SetCachePos( nPos );
 
diff --git a/sw/source/core/inc/swcache.hxx b/sw/source/core/inc/swcache.hxx
index 2744b9f2f318..aa0e4188d608 100644
--- a/sw/source/core/inc/swcache.hxx
+++ b/sw/source/core/inc/swcache.hxx
@@ -43,16 +43,16 @@
  * when destroying them.
  */
 
+#include <memory>
 #include <vector>
 
 #include <rtl/ustring.hxx>
 
 class SwCacheObj;
 
-typedef std::vector<SwCacheObj*> SwCacheObjArr;
 class SwCache
 {
-    SwCacheObjArr m_aCacheObjects;
+    std::vector<std::unique_ptr<SwCacheObj>> m_aCacheObjects;
     std::vector<sal_uInt16> m_aFreePositions; /// Free positions for the Insert if the maximum has not been reached
                                             /// Every time an object is deregistered, its position is added here
     SwCacheObj *m_pRealFirst;                 /// _ALWAYS_ the real first LRU
@@ -112,7 +112,7 @@ public:
     sal_uInt16 GetCurMax() const { return m_nCurMax; }
     SwCacheObj *First() { return m_pRealFirst; }
     static inline SwCacheObj *Next( SwCacheObj *pCacheObj);
-    SwCacheObj* operator[](sal_uInt16 nIndex) { return m_aCacheObjects[nIndex]; }
+    SwCacheObj* operator[](sal_uInt16 nIndex) { return m_aCacheObjects[nIndex].get(); }
     sal_uInt16 size() { return m_aCacheObjects.size(); }
 };
 
commit 50887c9010515fe9fe61b3067f502cd28333773a
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Jan 9 12:24:37 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Jan 10 08:16:19 2019 +0100

    use unique_ptr in ScRangeUtil::IsAbsTabArea
    
    Change-Id: I3a5f88eef1e7a8241921f2fed15a1ebc2c4c3445
    Reviewed-on: https://gerrit.libreoffice.org/66006
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/inc/rangeutl.hxx b/sc/inc/rangeutl.hxx
index feab1fa5f853..54aba7bf817c 100644
--- a/sc/inc/rangeutl.hxx
+++ b/sc/inc/rangeutl.hxx
@@ -51,7 +51,7 @@ public:
 
     static bool IsAbsTabArea    ( const OUString&   rAreaStr,
                                   const ScDocument* pDoc,
-                                  ScArea***         pppAreas,
+                                  std::unique_ptr<ScArea[]>* ppAreas,
                                   sal_uInt16*       pAreaCount,
                                   bool              bAcceptCellRef = false,
                                   ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 );
diff --git a/sc/source/core/tool/rangeutl.cxx b/sc/source/core/tool/rangeutl.cxx
index 5d6f74ef5b71..a29b33907869 100644
--- a/sc/source/core/tool/rangeutl.cxx
+++ b/sc/source/core/tool/rangeutl.cxx
@@ -86,7 +86,7 @@ void ScRangeUtil::CutPosString( const OUString&   theAreaStr,
 
 bool ScRangeUtil::IsAbsTabArea( const OUString&   rAreaStr,
                                 const ScDocument* pDoc,
-                                ScArea***       pppAreas,
+                                std::unique_ptr<ScArea[]>*  ppAreas,
                                 sal_uInt16*         pAreaCount,
                                 bool            /* bAcceptCellRef */,
                                 ScAddress::Details const & rDetails )
@@ -143,12 +143,12 @@ bool ScRangeUtil::IsAbsTabArea( const OUString&   rAreaStr,
 
                 bStrOk = true;
 
-                if ( pppAreas && pAreaCount ) // Array returned ?
+                if ( ppAreas && pAreaCount ) // Array returned ?
                 {
                     SCTAB       nStartTab   = aStartPos.Tab();
                     SCTAB       nEndTab     = aEndPos.Tab();
                     sal_uInt16      nTabCount   = static_cast<sal_uInt16>(nEndTab-nStartTab+1);
-                    ScArea**    theAreas    = new ScArea*[nTabCount];
+                    ppAreas->reset(new ScArea[nTabCount]);
                     SCTAB       nTab        = 0;
                     sal_uInt16      i           = 0;
                     ScArea      theArea( 0, aStartPos.Col(), aStartPos.Row(),
@@ -157,11 +157,10 @@ bool ScRangeUtil::IsAbsTabArea( const OUString&   rAreaStr,
                     nTab = nStartTab;
                     for ( i=0; i<nTabCount; i++ )
                     {
-                        theAreas[i] = new ScArea( theArea );
-                        theAreas[i]->nTab = nTab;
+                        (*ppAreas)[i] = theArea;
+                        (*ppAreas)[i].nTab = nTab;
                         nTab++;
                     }
-                    *pppAreas   = theAreas;
                     *pAreaCount = nTabCount;
                 }
             }
diff --git a/sc/source/ui/dbgui/consdlg.cxx b/sc/source/ui/dbgui/consdlg.cxx
index 43ebbe00c9f8..d1df2b6647a1 100644
--- a/sc/source/ui/dbgui/consdlg.cxx
+++ b/sc/source/ui/dbgui/consdlg.cxx
@@ -426,7 +426,7 @@ IMPL_LINK( ScConsolidateDlg, ClickHdl, Button*, pBtn, void )
         if ( !pEdDataArea->GetText().isEmpty() )
         {
             OUString    aNewEntry( pEdDataArea->GetText() );
-            ScArea**    ppAreas = nullptr;
+            std::unique_ptr<ScArea[]> ppAreas;
             sal_uInt16      nAreaCount = 0;
             const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
 
@@ -438,24 +438,17 @@ IMPL_LINK( ScConsolidateDlg, ClickHdl, Button*, pBtn, void )
 
                 for ( sal_uInt16 i=0; i<nAreaCount; i++ )
                 {
-                    OUString aNewArea;
+                    const ScArea& rArea = ppAreas[i];
+                    OUString aNewArea = ScRange( rArea.nColStart, rArea.nRowStart, rArea.nTab,
+                            rArea.nColEnd, rArea.nRowEnd, rArea.nTab
+                            ).Format(ScRefFlags::RANGE_ABS_3D, pDoc, eConv);
 
-                    if ( ppAreas[i] )
+                    if ( pLbConsAreas->GetEntryPos( aNewArea )
+                         == LISTBOX_ENTRY_NOTFOUND )
                     {
-                        const ScArea& rArea = *(ppAreas[i]);
-                        aNewArea = ScRange( rArea.nColStart, rArea.nRowStart, rArea.nTab,
-                                rArea.nColEnd, rArea.nRowEnd, rArea.nTab
-                                ).Format(ScRefFlags::RANGE_ABS_3D, pDoc, eConv);
-
-                        if ( pLbConsAreas->GetEntryPos( aNewArea )
-                             == LISTBOX_ENTRY_NOTFOUND )
-                        {
-                            pLbConsAreas->InsertEntry( aNewArea );
-                        }
-                        delete ppAreas[i];
+                        pLbConsAreas->InsertEntry( aNewArea );
                     }
                 }
-                delete [] ppAreas;
             }
             else if ( VerifyEdit( pEdDataArea ) )
             {


More information about the Libreoffice-commits mailing list