diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-25 13:23:34 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-26 08:58:31 +0200 |
commit | 0699a18c622149ac6dbc898bf920c47c45ccd5b9 (patch) | |
tree | 0aaa7b9d48c72da2d36f44934cc79a645b872a57 /i18npool/source | |
parent | a39166b98580c0b0f7af6830745962d17adef578 (diff) |
loplugin:useuniqueptr in lcl_LookupTableHelper
Change-Id: I8ee34ced61a23d7ade71b25f547c607cd4fe37bb
Reviewed-on: https://gerrit.libreoffice.org/60968
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'i18npool/source')
-rw-r--r-- | i18npool/source/localedata/localedata.cxx | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/i18npool/source/localedata/localedata.cxx b/i18npool/source/localedata/localedata.cxx index 75427fae14cc..11258ab7d9c4 100644 --- a/i18npool/source/localedata/localedata.cxx +++ b/i18npool/source/localedata/localedata.cxx @@ -481,11 +481,11 @@ public: oslGenericFunction getFunctionSymbolByName( const OUString& localeName, const sal_Char* pFunction, - LocaleDataLookupTableItem** pOutCachedItem ); + std::unique_ptr<LocaleDataLookupTableItem>* pOutCachedItem ); private: ::osl::Mutex maMutex; - ::std::vector< LocaleDataLookupTableItem* > maLookupTable; + ::std::vector< LocaleDataLookupTableItem > maLookupTable; }; // from instance.hxx: Helper base class for a late-initialized @@ -502,20 +502,14 @@ lcl_LookupTableHelper::lcl_LookupTableHelper() lcl_LookupTableHelper::~lcl_LookupTableHelper() { - std::vector<LocaleDataLookupTableItem*>::const_iterator aEnd(maLookupTable.end()); - std::vector<LocaleDataLookupTableItem*>::iterator aIter(maLookupTable.begin()); - - for ( ; aIter != aEnd; ++aIter ) { - LocaleDataLookupTableItem* pItem = *aIter; - delete pItem->module; - delete pItem; + for ( LocaleDataLookupTableItem& item : maLookupTable ) { + delete item.module; } - maLookupTable.clear(); } oslGenericFunction lcl_LookupTableHelper::getFunctionSymbolByName( const OUString& localeName, const sal_Char* pFunction, - LocaleDataLookupTableItem** pOutCachedItem ) + std::unique_ptr<LocaleDataLookupTableItem>* pOutCachedItem ) { OUString aFallback; bool bFallback = (localeName.indexOf( cUnder) < 0); @@ -540,14 +534,14 @@ oslGenericFunction lcl_LookupTableHelper::getFunctionSymbolByName( strlen(i.pLocale) + 1 + strlen(pFunction))); { ::osl::MutexGuard aGuard( maMutex ); - for (LocaleDataLookupTableItem* pCurrent : maLookupTable) + for (LocaleDataLookupTableItem & rCurrent : maLookupTable) { - if (pCurrent->dllName == i.pLib) + if (rCurrent.dllName == i.pLib) { OSL_ASSERT( pOutCachedItem ); if( pOutCachedItem ) { - (*pOutCachedItem) = new LocaleDataLookupTableItem( *pCurrent ); + (*pOutCachedItem).reset(new LocaleDataLookupTableItem( rCurrent )); (*pOutCachedItem)->localeName = i.pLocale; return (*pOutCachedItem)->module->getFunctionSymbol( aBuf.appendAscii( pFunction).append( cUnder). @@ -570,12 +564,11 @@ oslGenericFunction lcl_LookupTableHelper::getFunctionSymbolByName( if ( module->loadRelative(&thisModule, aBuf.makeStringAndClear()) ) { ::osl::MutexGuard aGuard( maMutex ); - LocaleDataLookupTableItem* pNewItem = new LocaleDataLookupTableItem(i.pLib, module, i.pLocale); - maLookupTable.push_back(pNewItem); + maLookupTable.emplace_back(i.pLib, module, i.pLocale); OSL_ASSERT( pOutCachedItem ); if( pOutCachedItem ) { - (*pOutCachedItem) = new LocaleDataLookupTableItem( *pNewItem ); + pOutCachedItem->reset(new LocaleDataLookupTableItem( maLookupTable.back() )); return module->getFunctionSymbol( aBuf.appendAscii(pFunction).append(cUnder). appendAscii((*pOutCachedItem)->localeName).makeStringAndClear()); @@ -1455,7 +1448,7 @@ oslGenericFunction LocaleDataImpl::getFunctionSymbol( const Locale& rLocale, con } oslGenericFunction pSymbol = nullptr; - LocaleDataLookupTableItem *pCachedItem = nullptr; + std::unique_ptr<LocaleDataLookupTableItem> pCachedItem; // Load function with name <func>_<lang>_<country> or <func>_<bcp47> and // fallbacks. @@ -1482,7 +1475,7 @@ oslGenericFunction LocaleDataImpl::getFunctionSymbol( const Locale& rLocale, con throw RuntimeException(); if (pCachedItem) - cachedItem.reset(pCachedItem); + cachedItem = std::move(pCachedItem); if (cachedItem.get()) cachedItem->aLocale = rLocale; @@ -1500,16 +1493,12 @@ LocaleDataImpl::getAllInstalledLocaleNames() // Check if the locale is really available and not just in the table, // don't allow fall backs. - LocaleDataLookupTableItem *pCachedItem = nullptr; + std::unique_ptr<LocaleDataLookupTableItem> pCachedItem; if (lcl_LookupTableStatic::get().getFunctionSymbolByName( name, "getLocaleItem", &pCachedItem )) { if( pCachedItem ) - cachedItem.reset( pCachedItem ); + cachedItem = std::move( pCachedItem ); seq[nInstalled++] = LanguageTag::convertToLocale( name.replace( cUnder, cHyphen), false); } - else - { - delete pCachedItem; - } } if ( nInstalled < nbOfLocales ) seq.realloc( nInstalled ); // reflect reality |