From c91f8e55fa9a335a4cc10f70e95e8a60a658c13b Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 26 Mar 2018 11:47:49 +0200 Subject: loplugin:useuniqueptr in MergeDataHashMap Change-Id: I263c187bab997b6ab929ca04788214d7418cb449 Reviewed-on: https://gerrit.libreoffice.org/51928 Tested-by: Jenkins Reviewed-by: Noel Grandin --- l10ntools/inc/export.hxx | 4 ++-- l10ntools/source/merge.cxx | 12 +++++------- 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'l10ntools') 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 HashMap_t; + typedef std::unordered_map> HashMap_t; public: MergeDataHashMap() @@ -165,7 +165,7 @@ class MergeDataHashMap typedef HashMap_t::iterator iterator; typedef HashMap_t::const_iterator const_iterator; - std::pair insert(const OString& rKey, MergeData* pMergeData); + std::pair insert(const OString& rKey, std::unique_ptr 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::insert(const OString& rKey, MergeData* pMergeData) +std::pair MergeDataHashMap::insert(const OString& rKey, std::unique_ptr pMergeData) { - std::pair aTemp = m_aHashMap.emplace( rKey, pMergeData ); + std::pair 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 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(pData) ); } -- cgit