summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2018-08-15 21:32:27 +0300
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-08-20 17:12:11 +0200
commit0787ce8814e37972a0c968f60008d4e8722b6e27 (patch)
tree9d2803ebda8813e6b3f2bc2e6f8a74953b2931c1 /scripting
parentd2c9c60fefb9687adbde4be61ed66a5123a2587f (diff)
Simplify containers iterations, tdf#96099 follow-up
Use range-based loop or replace with std::any_of, std::find and std::find_if where applicable. Change-Id: I2f80788c49d56094c29b102eb96a7a7c079567c6 Reviewed-on: https://gerrit.libreoffice.org/59143 Tested-by: Jenkins Reviewed-by: Michael Meeks <michael.meeks@collabora.com> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'scripting')
-rw-r--r--scripting/source/provider/BrowseNodeFactoryImpl.cxx7
-rw-r--r--scripting/source/stringresource/stringresource.cxx59
2 files changed, 21 insertions, 45 deletions
diff --git a/scripting/source/provider/BrowseNodeFactoryImpl.cxx b/scripting/source/provider/BrowseNodeFactoryImpl.cxx
index 122e3e247279..b27ac817329f 100644
--- a/scripting/source/provider/BrowseNodeFactoryImpl.cxx
+++ b/scripting/source/provider/BrowseNodeFactoryImpl.cxx
@@ -195,11 +195,10 @@ public:
Sequence< Reference< browse::XBrowseNode > > children( m_hBNA->size() );
sal_Int32 index = 0;
- auto it = m_vStr.begin();
-
- for ( ; it != m_vStr.end(); ++it, index++ )
+ for ( auto& str : m_vStr )
{
- children[ index ].set( m_hBNA->find( *it )->second );
+ children[ index ].set( m_hBNA->find( str )->second );
+ ++index;
}
return children;
diff --git a/scripting/source/stringresource/stringresource.cxx b/scripting/source/stringresource/stringresource.cxx
index 36fcde4f2015..8fdfdec22526 100644
--- a/scripting/source/stringresource/stringresource.cxx
+++ b/scripting/source/stringresource/stringresource.cxx
@@ -112,17 +112,11 @@ StringResourceImpl::StringResourceImpl( const Reference< XComponentContext >& rx
StringResourceImpl::~StringResourceImpl()
{
- for( auto it = m_aLocaleItemVector.begin(); it != m_aLocaleItemVector.end(); ++it )
- {
- LocaleItem* pLocaleItem = *it;
+ for( auto& pLocaleItem : m_aLocaleItemVector )
delete pLocaleItem;
- }
- for( auto it = m_aDeletedLocaleItemVector.begin(); it != m_aDeletedLocaleItemVector.end(); ++it )
- {
- LocaleItem* pLocaleItem = *it;
+ for( auto& pLocaleItem : m_aDeletedLocaleItemVector )
delete pLocaleItem;
- }
}
@@ -291,9 +285,8 @@ Sequence< Locale > StringResourceImpl::getLocales( )
Sequence< Locale > aLocalSeq( nSize );
Locale* pLocales = aLocalSeq.getArray();
int iTarget = 0;
- for( auto it = m_aLocaleItemVector.cbegin(); it != m_aLocaleItemVector.cend(); ++it )
+ for( auto& pLocaleItem : m_aLocaleItemVector )
{
- LocaleItem* pLocaleItem = *it;
pLocales[iTarget] = pLocaleItem->m_locale;
iTarget++;
}
@@ -511,9 +504,8 @@ void StringResourceImpl::removeLocale( const Locale& locale )
m_pDefaultLocaleItem == pRemoveItem )
{
LocaleItem* pFallbackItem = nullptr;
- for( auto it = m_aLocaleItemVector.begin(); it != m_aLocaleItemVector.end(); ++it )
+ for( auto& pLocaleItem : m_aLocaleItemVector )
{
- LocaleItem* pLocaleItem = *it;
if( pLocaleItem != pRemoveItem )
{
pFallbackItem = pLocaleItem;
@@ -606,9 +598,8 @@ LocaleItem* StringResourceImpl::getItemForLocale
LocaleItem* pRetItem = nullptr;
// Search for locale
- for( auto it = m_aLocaleItemVector.cbegin(); it != m_aLocaleItemVector.cend(); ++it )
+ for( auto& pLocaleItem : m_aLocaleItemVector )
{
- LocaleItem* pLocaleItem = *it;
if( pLocaleItem )
{
Locale& cmp_locale = pLocaleItem->m_locale;
@@ -637,10 +628,10 @@ LocaleItem* StringResourceImpl::getClosestMatchItemForLocale( const Locale& loca
::std::vector< Locale > aLocales( m_aLocaleItemVector.size());
size_t i = 0;
- for( auto it = m_aLocaleItemVector.cbegin(); it != m_aLocaleItemVector.cend(); ++it, ++i )
+ for( auto& pLocaleItem : m_aLocaleItemVector )
{
- LocaleItem* pLocaleItem = *it;
aLocales[i] = (pLocaleItem ? pLocaleItem->m_locale : Locale());
+ ++i;
}
::std::vector< Locale >::const_iterator iFound( LanguageTag::getMatchingFallback( aLocales, locale));
if (iFound != aLocales.end())
@@ -901,10 +892,8 @@ void StringResourcePersistenceImpl::implStoreAtStorage
// Delete files for deleted locales
if( bUsedForStore )
{
- while( m_aDeletedLocaleItemVector.size() > 0 )
+ for( auto& pLocaleItem : m_aDeletedLocaleItemVector )
{
- auto it = m_aDeletedLocaleItemVector.begin();
- LocaleItem* pLocaleItem = *it;
if( pLocaleItem != nullptr )
{
OUString aStreamName = implGetFileNameForLocaleItem( pLocaleItem, m_aNameBase );
@@ -917,15 +906,14 @@ void StringResourcePersistenceImpl::implStoreAtStorage
catch( Exception& )
{}
- m_aDeletedLocaleItemVector.erase( it );
delete pLocaleItem;
}
}
+ m_aDeletedLocaleItemVector.clear();
}
- for( auto it = m_aLocaleItemVector.cbegin(); it != m_aLocaleItemVector.cend(); ++it )
+ for( auto& pLocaleItem : m_aLocaleItemVector )
{
- LocaleItem* pLocaleItem = *it;
if( pLocaleItem != nullptr && (bStoreAll || pLocaleItem->m_bModified) &&
loadLocale( pLocaleItem ) )
{
@@ -960,10 +948,8 @@ void StringResourcePersistenceImpl::implStoreAtStorage
// Delete files for changed defaults
if( bUsedForStore )
{
- for( auto it = m_aChangedDefaultLocaleVector.begin();
- it != m_aChangedDefaultLocaleVector.end(); ++it )
+ for( auto& pLocaleItem : m_aChangedDefaultLocaleVector )
{
- LocaleItem* pLocaleItem = *it;
if( pLocaleItem != nullptr )
{
OUString aStreamName = implGetFileNameForLocaleItem( pLocaleItem, m_aNameBase );
@@ -1021,10 +1007,8 @@ void StringResourcePersistenceImpl::implKillRemovedLocaleFiles
)
{
// Delete files for deleted locales
- while( m_aDeletedLocaleItemVector.size() > 0 )
+ for( auto& pLocaleItem : m_aDeletedLocaleItemVector )
{
- auto it = m_aDeletedLocaleItemVector.begin();
- LocaleItem* pLocaleItem = *it;
if( pLocaleItem != nullptr )
{
OUString aCompleteFileName =
@@ -1032,10 +1016,10 @@ void StringResourcePersistenceImpl::implKillRemovedLocaleFiles
if( xFileAccess->exists( aCompleteFileName ) )
xFileAccess->kill( aCompleteFileName );
- m_aDeletedLocaleItemVector.erase( it );
delete pLocaleItem;
}
}
+ m_aDeletedLocaleItemVector.clear();
}
void StringResourcePersistenceImpl::implKillChangedDefaultFiles
@@ -1046,10 +1030,8 @@ void StringResourcePersistenceImpl::implKillChangedDefaultFiles
)
{
// Delete files for changed defaults
- for( auto it = m_aChangedDefaultLocaleVector.begin();
- it != m_aChangedDefaultLocaleVector.end(); ++it )
+ for( auto& pLocaleItem : m_aChangedDefaultLocaleVector )
{
- LocaleItem* pLocaleItem = *it;
if( pLocaleItem != nullptr )
{
OUString aCompleteFileName =
@@ -1078,9 +1060,8 @@ void StringResourcePersistenceImpl::implStoreAtLocation
if( bUsedForStore || bKillAll )
implKillRemovedLocaleFiles( Location, aNameBase, xFileAccess );
- for( auto it = m_aLocaleItemVector.cbegin(); it != m_aLocaleItemVector.cend(); ++it )
+ for( auto& pLocaleItem : m_aLocaleItemVector )
{
- LocaleItem* pLocaleItem = *it;
if( pLocaleItem != nullptr && (bStoreAll || bKillAll || pLocaleItem->m_bModified) &&
loadLocale( pLocaleItem ) )
{
@@ -1270,10 +1251,8 @@ Sequence< sal_Int8 > StringResourcePersistenceImpl::exportBinary( )
sal_Int32 iLocale = 0;
sal_Int32 iDefault = 0;
- for( auto it = m_aLocaleItemVector.cbegin();
- it != m_aLocaleItemVector.cend(); ++it,++iLocale )
+ for( auto& pLocaleItem : m_aLocaleItemVector )
{
- LocaleItem* pLocaleItem = *it;
if( pLocaleItem != nullptr && loadLocale( pLocaleItem ) )
{
if( m_pDefaultLocaleItem == pLocaleItem )
@@ -1284,6 +1263,7 @@ Sequence< sal_Int8 > StringResourcePersistenceImpl::exportBinary( )
pLocaleDataSeq[iLocale] = aLocaleOut.closeAndGetData();
}
+ ++iLocale;
}
// Write header
@@ -1568,12 +1548,9 @@ bool checkNamingSceme( const OUString& aName, const OUString& aNameBase,
void StringResourcePersistenceImpl::implLoadAllLocales()
{
- for( auto it = m_aLocaleItemVector.begin(); it != m_aLocaleItemVector.end(); ++it )
- {
- LocaleItem* pLocaleItem = *it;
+ for( auto& pLocaleItem : m_aLocaleItemVector )
if( pLocaleItem != nullptr )
loadLocale( pLocaleItem );
- }
}
// Scan locale properties files helper