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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Jan 16 09:27:42 UTC 2019


 sc/inc/autoform.hxx                   |    2 +-
 sc/source/core/tool/autoform.cxx      |   13 ++++++-------
 sc/source/ui/miscdlgs/scuiautofmt.cxx |   19 +++++++------------
 sc/source/ui/unoobj/afmtuno.cxx       |   10 +++++-----
 4 files changed, 19 insertions(+), 25 deletions(-)

New commits:
commit f8fcff9640f391a6bab7d9401d2656b3781c50cf
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Jan 15 10:02:43 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Jan 16 10:27:15 2019 +0100

    pass ScAutoFormatData around with unique_ptr
    
    Change-Id: Ia112f42560955029a4a337a080a3aa0659db06b8
    Reviewed-on: https://gerrit.libreoffice.org/66419
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/inc/autoform.hxx b/sc/inc/autoform.hxx
index 18f2bb6ee9a4..b1d22390573c 100644
--- a/sc/inc/autoform.hxx
+++ b/sc/inc/autoform.hxx
@@ -333,7 +333,7 @@ public:
     iterator find(const ScAutoFormatData* pData);
     iterator find(const OUString& rName);
 
-    bool insert(ScAutoFormatData* pNew);
+    iterator insert(std::unique_ptr<ScAutoFormatData> pNew);
     void erase(const iterator& it);
 
     size_t size() const;
diff --git a/sc/source/core/tool/autoform.cxx b/sc/source/core/tool/autoform.cxx
index c84a32939016..03a17010e37b 100644
--- a/sc/source/core/tool/autoform.cxx
+++ b/sc/source/core/tool/autoform.cxx
@@ -853,7 +853,7 @@ ScAutoFormat::ScAutoFormat() :
     mbSaveLater(false)
 {
     //  create default autoformat
-    ScAutoFormatData* pData = new ScAutoFormatData;
+    std::unique_ptr<ScAutoFormatData> pData(new ScAutoFormatData);
     OUString aName(ScResId(STR_STYLENAME_STANDARD));
     pData->SetName(aName);
 
@@ -929,7 +929,7 @@ ScAutoFormat::ScAutoFormat() :
         }
     }
 
-    insert(pData);
+    insert(std::move(pData));
 }
 
 bool DefaultFirstEntry::operator() (const OUString& left, const OUString& right) const
@@ -985,10 +985,10 @@ ScAutoFormat::iterator ScAutoFormat::find(const OUString& rName)
     return m_Data.find(rName);
 }
 
-bool ScAutoFormat::insert(ScAutoFormatData* pNew)
+ScAutoFormat::iterator ScAutoFormat::insert(std::unique_ptr<ScAutoFormatData> pNew)
 {
     OUString aName = pNew->GetName();
-    return m_Data.insert(std::make_pair(aName, std::unique_ptr<ScAutoFormatData>(pNew))).second;
+    return m_Data.insert(std::make_pair(aName, std::move(pNew))).first;
 }
 
 void ScAutoFormat::erase(const iterator& it)
@@ -1062,15 +1062,14 @@ void ScAutoFormat::Load()
             {
                 m_aVersions.Load( rStream, nVal );        // item versions
 
-                ScAutoFormatData* pData;
                 sal_uInt16 nCnt = 0;
                 rStream.ReadUInt16( nCnt );
                 bRet = (rStream.GetError() == ERRCODE_NONE);
                 for (sal_uInt16 i=0; bRet && (i < nCnt); i++)
                 {
-                    pData = new ScAutoFormatData();
+                    std::unique_ptr<ScAutoFormatData> pData(new ScAutoFormatData());
                     bRet = pData->Load(rStream, m_aVersions);
-                    insert(pData);
+                    insert(std::move(pData));
                 }
             }
         }
diff --git a/sc/source/ui/miscdlgs/scuiautofmt.cxx b/sc/source/ui/miscdlgs/scuiautofmt.cxx
index 2b08756b4d87..f4a1828cdd7b 100644
--- a/sc/source/ui/miscdlgs/scuiautofmt.cxx
+++ b/sc/source/ui/miscdlgs/scuiautofmt.cxx
@@ -228,17 +228,16 @@ IMPL_LINK_NOARG(ScAutoFormatDlg, AddHdl, Button*, void)
 
                 if ( !aFormatName.isEmpty() && aFormatName != aStrStandard && pFormat->find(aFormatName) == pFormat->end() )
                 {
-                    ScAutoFormatData* pNewData
-                        = new ScAutoFormatData( *pSelFmtData );
+                    std::unique_ptr<ScAutoFormatData> pNewData(
+                        new ScAutoFormatData( *pSelFmtData ));
 
                     pNewData->SetName( aFormatName );
-                    bFmtInserted = pFormat->insert(pNewData);
+                    ScAutoFormat::iterator it = pFormat->insert(std::move(pNewData));
+                    bFmtInserted = it != pFormat->end();
 
                     if ( bFmtInserted )
                     {
-                        ScAutoFormat::const_iterator it = pFormat->find(pNewData);
-                        ScAutoFormat::const_iterator itBeg = pFormat->begin();
-                        size_t nPos = std::distance(itBeg, it);
+                        size_t nPos = std::distance(pFormat->begin(), it);
                         m_pLbFormat->InsertEntry(aFormatName, nPos);
                         m_pLbFormat->SelectEntry( aFormatName );
                         m_pBtnAdd->Disable();
@@ -252,9 +251,6 @@ IMPL_LINK_NOARG(ScAutoFormatDlg, AddHdl, Button*, void)
                         SelFmtHdl( *m_pLbFormat.get() );
                         bOk = true;
                     }
-                    else
-                        delete pNewData;
-
                 }
 
                 if ( !bFmtInserted )
@@ -344,8 +340,7 @@ IMPL_LINK_NOARG(ScAutoFormatDlg, RenameHdl, Button*, void)
 
                     m_pLbFormat->RemoveEntry(nIndex );
                     const ScAutoFormatData* p = pFormat->findByIndex(nIndex);
-                    ScAutoFormatData* pNewData
-                        = new ScAutoFormatData(*p);
+                    std::unique_ptr<ScAutoFormatData> pNewData(new ScAutoFormatData(*p));
 
                     it = pFormat->begin();
                     std::advance(it, nIndex);
@@ -353,7 +348,7 @@ IMPL_LINK_NOARG(ScAutoFormatDlg, RenameHdl, Button*, void)
 
                     pNewData->SetName( aFormatName );
 
-                    pFormat->insert(pNewData);
+                    pFormat->insert(std::move(pNewData));
 
                     m_pLbFormat->SetUpdateMode(false);
                     m_pLbFormat->Clear();
diff --git a/sc/source/ui/unoobj/afmtuno.cxx b/sc/source/ui/unoobj/afmtuno.cxx
index 81aee84f9a3d..56c711623df0 100644
--- a/sc/source/ui/unoobj/afmtuno.cxx
+++ b/sc/source/ui/unoobj/afmtuno.cxx
@@ -224,10 +224,10 @@ void SAL_CALL ScAutoFormatsObj::insertByName( const OUString& aName, const uno::
                 throw container::ElementExistException();
             }
 
-            ScAutoFormatData* pNew = new ScAutoFormatData();
+            std::unique_ptr<ScAutoFormatData> pNew(new ScAutoFormatData());
             pNew->SetName( aName );
 
-            if (pFormats->insert(pNew))
+            if (pFormats->insert(std::move(pNew)) != pFormats->end())
             {
                 //! notify to other objects
                 pFormats->Save();
@@ -493,13 +493,13 @@ void SAL_CALL ScAutoFormatObj::setName( const OUString& aNewName )
     ScAutoFormatData *const pData = it->second.get();
     OSL_ENSURE(pData,"AutoFormat data not available");
 
-    ScAutoFormatData* pNew = new ScAutoFormatData(*pData);
+    std::unique_ptr<ScAutoFormatData> pNew(new ScAutoFormatData(*pData));
     pNew->SetName( aNewName );
 
     pFormats->erase(it);
-    if (pFormats->insert(pNew))
+    it = pFormats->insert(std::move(pNew));
+    if (it != pFormats->end())
     {
-        it = pFormats->find(pNew);
         ScAutoFormat::iterator itBeg = pFormats->begin();
         nFormatIndex = std::distance(itBeg, it);
 


More information about the Libreoffice-commits mailing list