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

Noel Grandin noel.grandin at collabora.co.uk
Tue Mar 27 07:55:19 UTC 2018


 l10ntools/inc/export.hxx        |    4 ++--
 l10ntools/source/merge.cxx      |   12 +++++-------
 sc/inc/rechead.hxx              |    3 ++-
 sc/source/core/tool/rechead.cxx |    6 +++---
 4 files changed, 12 insertions(+), 13 deletions(-)

New commits:
commit c91f8e55fa9a335a4cc10f70e95e8a60a658c13b
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Mon Mar 26 11:47:49 2018 +0200

    loplugin:useuniqueptr in MergeDataHashMap
    
    Change-Id: I263c187bab997b6ab929ca04788214d7418cb449
    Reviewed-on: https://gerrit.libreoffice.org/51928
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/l10ntools/inc/export.hxx b/l10ntools/inc/export.hxx
index 0ed0f45c5175..5a9389ff7d19 100644
--- a/l10ntools/inc/export.hxx
+++ b/l10ntools/inc/export.hxx
@@ -151,7 +151,7 @@ class MergeData;
 class MergeDataHashMap
 {
     private:
-        typedef std::unordered_map<OString, MergeData*> HashMap_t;
+        typedef std::unordered_map<OString, std::unique_ptr<MergeData>> HashMap_t;
 
     public:
         MergeDataHashMap()
@@ -165,7 +165,7 @@ class MergeDataHashMap
         typedef HashMap_t::iterator iterator;
         typedef HashMap_t::const_iterator const_iterator;
 
-        std::pair<iterator,bool> insert(const OString& rKey, MergeData* pMergeData);
+        std::pair<iterator,bool> insert(const OString& rKey, std::unique_ptr<MergeData> pMergeData);
         iterator const & find(const OString& rKey);
 
         iterator begin() {return m_aHashMap.begin();}
diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx
index 66aca214467d..4e55b45a6942 100644
--- a/l10ntools/source/merge.cxx
+++ b/l10ntools/source/merge.cxx
@@ -111,9 +111,9 @@ OString MergeEntrys::GetQTZText(const ResData& rResData, const OString& rOrigTex
 // class MergeDataHashMap
 
 
-std::pair<MergeDataHashMap::iterator,bool> MergeDataHashMap::insert(const OString& rKey, MergeData* pMergeData)
+std::pair<MergeDataHashMap::iterator,bool> MergeDataHashMap::insert(const OString& rKey, std::unique_ptr<MergeData> pMergeData)
 {
-    std::pair<iterator,bool> aTemp = m_aHashMap.emplace( rKey, pMergeData );
+    std::pair<iterator,bool> aTemp = m_aHashMap.emplace( rKey, std::move(pMergeData) );
     if( m_aHashMap.size() == 1 )
     {
         // When first insert, set an iterator to the first element
@@ -296,8 +296,6 @@ MergeDataFile::MergeDataFile(
 
 MergeDataFile::~MergeDataFile()
 {
-    for (auto const& elem : aMap)
-        delete elem.second;
 }
 
 std::vector<OString> MergeDataFile::GetLanguages() const
@@ -325,7 +323,7 @@ MergeData *MergeDataFile::GetMergeData( ResData *pResData , bool bCaseSensitive
     {
         pResData->sGId = sOldG;
         pResData->sId = sOldL;
-        return mit->second;
+        return mit->second.get();
     }
     pResData->sGId = sOldG;
     pResData->sId = sOldL;
@@ -366,14 +364,14 @@ void MergeDataFile::InsertEntry(
     {
         MergeDataHashMap::const_iterator mit = aMap.find( sKey );
         if(mit != aMap.end())
-            pData = mit->second;
+            pData = mit->second.get();
 
     }
 
     if( !pData )
     {
         pData = new MergeData;
-        aMap.insert( sKey, pData );
+        aMap.insert( sKey, std::unique_ptr<MergeData>(pData) );
     }
 
 
commit 0f87f895380833084b64145c686f0ba5993737ca
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Fri Mar 23 16:35:01 2018 +0200

    loplugin:useuniqueptr in ScMultipleReadHeader
    
    Change-Id: I517593a910ed5783f256722bad915be2232f290e
    Reviewed-on: https://gerrit.libreoffice.org/51913
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/inc/rechead.hxx b/sc/inc/rechead.hxx
index 950620276fae..c6839e750b80 100644
--- a/sc/inc/rechead.hxx
+++ b/sc/inc/rechead.hxx
@@ -53,7 +53,8 @@ private:
     SvStream&           rStream;
     std::unique_ptr<sal_uInt8[]>
                         pBuf;
-    SvMemoryStream*     pMemStream;
+    std::unique_ptr<SvMemoryStream>
+                        pMemStream;
     sal_uLong           nEndPos;
     sal_uLong           nEntryEnd;
     sal_uLong           nTotalEnd;
diff --git a/sc/source/core/tool/rechead.cxx b/sc/source/core/tool/rechead.cxx
index 42b2b4cf6f0e..5e2262d4d8a6 100644
--- a/sc/source/core/tool/rechead.cxx
+++ b/sc/source/core/tool/rechead.cxx
@@ -41,7 +41,7 @@ ScMultipleReadHeader::ScMultipleReadHeader(SvStream& rNewStream) :
             rStream.SetError( SVSTREAM_FILEFORMAT_ERROR );
 
         //  everything to 0, so  BytesLeft() aborts at least
-        pBuf = nullptr; pMemStream = nullptr;
+        pBuf = nullptr; pMemStream.reset();
         nEntryEnd = nDataPos;
     }
     else
@@ -50,7 +50,7 @@ ScMultipleReadHeader::ScMultipleReadHeader(SvStream& rNewStream) :
         rStream.ReadUInt32( nSizeTableLen );
         pBuf.reset( new sal_uInt8[nSizeTableLen] );
         rStream.ReadBytes( pBuf.get(), nSizeTableLen );
-        pMemStream = new SvMemoryStream( pBuf.get(), nSizeTableLen, StreamMode::READ );
+        pMemStream.reset(new SvMemoryStream( pBuf.get(), nSizeTableLen, StreamMode::READ ));
     }
 
     nEndPos = rStream.Tell();
@@ -65,7 +65,7 @@ ScMultipleReadHeader::~ScMultipleReadHeader()
         if ( rStream.GetError() == ERRCODE_NONE )
             rStream.SetError( SCWARN_IMPORT_INFOLOST );
     }
-    delete pMemStream;
+    pMemStream.reset();
 
     rStream.Seek(nEndPos);
 }


More information about the Libreoffice-commits mailing list