diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2018-10-14 12:00:03 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-10-14 17:30:32 +0200 |
commit | 19be86249dcc5b13b3c95f5469600fa2bc1b749b (patch) | |
tree | e1468590650eea60e3897a8cb8b7c36bb9ab996b /vcl/unx/generic | |
parent | 7758115d15ded2afd81946df0865ecc831b179aa (diff) |
Simplify containers iterations in vcl
Use range-based loop or replace with STL functions.
Change-Id: Ide2f89194238ae6a1f21e8132e2297710d9e6dcd
Reviewed-on: https://gerrit.libreoffice.org/61756
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl/unx/generic')
-rw-r--r-- | vcl/unx/generic/dtrans/X11_selection.cxx | 11 | ||||
-rw-r--r-- | vcl/unx/generic/fontmanager/fontconfig.cxx | 4 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/cairotextrender.cxx | 8 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/salbmp.cxx | 11 | ||||
-rw-r--r-- | vcl/unx/generic/printer/ppdparser.cxx | 25 | ||||
-rw-r--r-- | vcl/unx/generic/printer/printerinfomanager.cxx | 35 |
6 files changed, 39 insertions, 55 deletions
diff --git a/vcl/unx/generic/dtrans/X11_selection.cxx b/vcl/unx/generic/dtrans/X11_selection.cxx index f7c0b6db6a8e..b77e542f7807 100644 --- a/vcl/unx/generic/dtrans/X11_selection.cxx +++ b/vcl/unx/generic/dtrans/X11_selection.cxx @@ -457,13 +457,10 @@ SelectionManager::~SelectionManager() { osl::MutexGuard aGuard( *osl::Mutex::getGlobalMutex() ); - std::unordered_map< OUString, SelectionManager* >::iterator it; - for( it = getInstances().begin(); it != getInstances().end(); ++it ) - if( it->second == this ) - { - getInstances().erase( it ); - break; - } + auto it = std::find_if(getInstances().begin(), getInstances().end(), + [&](const std::pair< OUString, SelectionManager* >& rInstance) { return rInstance.second == this; }); + if( it != getInstances().end() ) + getInstances().erase( it ); } if( m_aThread ) diff --git a/vcl/unx/generic/fontmanager/fontconfig.cxx b/vcl/unx/generic/fontmanager/fontconfig.cxx index ca40710aa0bd..76598746bec6 100644 --- a/vcl/unx/generic/fontmanager/fontconfig.cxx +++ b/vcl/unx/generic/fontmanager/fontconfig.cxx @@ -560,9 +560,7 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int>& o std::unique_ptr<PrintFont> xUpdate; - auto second_font = aFonts.begin(); - ++second_font; - if (second_font == aFonts.end()) // one font + if (aFonts.size() == 1) // one font xUpdate = std::move(aFonts.front()); else // more than one font { diff --git a/vcl/unx/generic/gdi/cairotextrender.cxx b/vcl/unx/generic/gdi/cairotextrender.cxx index 40e1c5a8db3b..b7356eda56a5 100644 --- a/vcl/unx/generic/gdi/cairotextrender.cxx +++ b/vcl/unx/generic/gdi/cairotextrender.cxx @@ -129,10 +129,10 @@ void CairoFontsCache::CacheFont(void *pFont, const CairoFontsCache::CacheId &rId void* CairoFontsCache::FindCachedFont(const CairoFontsCache::CacheId &rId) { - LRUFonts::iterator aEnd = maLRUFonts.end(); - for (LRUFonts::iterator aI = maLRUFonts.begin(); aI != aEnd; ++aI) - if (aI->second == rId) - return aI->first; + auto aI = std::find_if(maLRUFonts.begin(), maLRUFonts.end(), + [&rId](const LRUFonts::value_type& rFont) { return rFont.second == rId; }); + if (aI != maLRUFonts.end()) + return aI->first; return nullptr; } diff --git a/vcl/unx/generic/gdi/salbmp.cxx b/vcl/unx/generic/gdi/salbmp.cxx index a99dba3e77f2..8dfd446c4cd6 100644 --- a/vcl/unx/generic/gdi/salbmp.cxx +++ b/vcl/unx/generic/gdi/salbmp.cxx @@ -1077,14 +1077,11 @@ void ImplSalBitmapCache::ImplAdd( X11SalBitmap* pBmp ) void ImplSalBitmapCache::ImplRemove( X11SalBitmap const * pBmp ) { - for( auto it = maBmpList.begin(); it != maBmpList.end(); ++it) + auto it = std::find(maBmpList.begin(), maBmpList.end(), pBmp); + if( it != maBmpList.end() ) { - if( *it == pBmp ) - { - (*it)->ImplRemovedFromCache(); - maBmpList.erase( it ); - break; - } + (*it)->ImplRemovedFromCache(); + maBmpList.erase( it ); } } diff --git a/vcl/unx/generic/printer/ppdparser.cxx b/vcl/unx/generic/printer/ppdparser.cxx index 8b01494ddb44..105a350a27d6 100644 --- a/vcl/unx/generic/printer/ppdparser.cxx +++ b/vcl/unx/generic/printer/ppdparser.cxx @@ -1215,9 +1215,8 @@ void PPDParser::parse( ::std::vector< OString >& rLines ) } // second pass: fill in defaults - for( line = rLines.begin(); line != rLines.end(); ++line ) + for( const auto& aLine : rLines ) { - OString aLine(*line); if (aLine.startsWith("*Default")) { SAL_INFO("vcl.unx.print", "Found a default: '" << aLine << "'"); @@ -1598,14 +1597,10 @@ void PPDKey::eraseValue( const OUString& rOption ) if( it == m_aValues.end() ) return; - for( PPDKey::value_type::iterator vit = m_aOrderedValues.begin(); vit != m_aOrderedValues.end(); ++vit ) - { - if( *vit == &(it->second ) ) - { - m_aOrderedValues.erase( vit ); - break; - } - } + auto vit = std::find(m_aOrderedValues.begin(), m_aOrderedValues.end(), &(it->second )); + if( vit != m_aOrderedValues.end() ) + m_aOrderedValues.erase( vit ); + m_aValues.erase( it ); } @@ -1649,10 +1644,12 @@ PPDContext& PPDContext::operator=( PPDContext&& rCopy ) const PPDKey* PPDContext::getModifiedKey( int n ) const { - hash_type::const_iterator it; - for( it = m_aCurrentValues.begin(); it != m_aCurrentValues.end() && n--; ++it ) - ; - return it != m_aCurrentValues.end() ? it->first : nullptr; + if( m_aCurrentValues.size() < static_cast<hash_type::size_type>(n) ) + return nullptr; + + hash_type::const_iterator it = m_aCurrentValues.begin(); + std::advance(it, n); + return it->first; } void PPDContext::setParser( const PPDParser* pParser ) diff --git a/vcl/unx/generic/printer/printerinfomanager.cxx b/vcl/unx/generic/printer/printerinfomanager.cxx index e97a7888a13f..30272c739029 100644 --- a/vcl/unx/generic/printer/printerinfomanager.cxx +++ b/vcl/unx/generic/printer/printerinfomanager.cxx @@ -712,30 +712,25 @@ static void lpgetSysQueueTokenHandler( // find _all: line OString aAllLine( "_all:" ); OString aAllAttr( "all=" ); - for( std::vector< OString >::const_iterator it = i_rLines.begin(); - it != i_rLines.end(); ++it ) + auto it = std::find_if(i_rLines.begin(), i_rLines.end(), + [&aAllLine](const OString& rLine) { return rLine.indexOf( aAllLine, 0 ) == 0; }); + if( it != i_rLines.end() ) { - if( it->indexOf( aAllLine, 0 ) == 0 ) + // now find the "all" attribute + ++it; + it = std::find_if(it, i_rLines.end(), + [&aAllAttr](const OString& rLine) { return WhitespaceToSpace( rLine ).startsWith( aAllAttr ); }); + if( it != i_rLines.end() ) { - // now find the "all" attribute - ++it; - while( it != i_rLines.end() ) + // insert the comma separated entries into the set of printers to use + OString aClean( WhitespaceToSpace( *it ) ); + sal_Int32 nPos = aAllAttr.getLength(); + while( nPos != -1 ) { - OString aClean( WhitespaceToSpace( *it ) ); - if( aClean.startsWith( aAllAttr ) ) - { - // insert the comma separated entries into the set of printers to use - sal_Int32 nPos = aAllAttr.getLength(); - while( nPos != -1 ) - { - OString aTok( aClean.getToken( 0, ',', nPos ) ); - if( !aTok.isEmpty() ) - aOnlySet.insert( OStringToOUString( aTok, aEncoding ) ); - } - break; - } + OString aTok( aClean.getToken( 0, ',', nPos ) ); + if( !aTok.isEmpty() ) + aOnlySet.insert( OStringToOUString( aTok, aEncoding ) ); } - break; } } |