diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2018-10-24 00:49:27 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-10-24 14:45:19 +0200 |
commit | 86192438d16ec160d6b59d08735e770ee05ac113 (patch) | |
tree | 25dbb9dde6631d49b0ea8483c8f3018def3ddd0d /tools/source/stream/strmunx.cxx | |
parent | 6f50961e69406a17d6ec998956a6b33208b1001b (diff) |
Simplify containers iterations in test..tools
Use range-based loop or replace with STL functions.
Change-Id: If8fac9236a4696c8e56c0e81c60c429782581b96
Reviewed-on: https://gerrit.libreoffice.org/62262
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'tools/source/stream/strmunx.cxx')
-rw-r--r-- | tools/source/stream/strmunx.cxx | 47 |
1 files changed, 16 insertions, 31 deletions
diff --git a/tools/source/stream/strmunx.cxx b/tools/source/stream/strmunx.cxx index 77c30850a1ba..c682071a112c 100644 --- a/tools/source/stream/strmunx.cxx +++ b/tools/source/stream/strmunx.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <algorithm> #include <stdio.h> #include <string.h> #include <sys/stat.h> @@ -110,33 +111,25 @@ bool lockFile( sal_uInt64 const nStart, sal_uInt64 const nEnd, SvFileStream* pSt osl::MutexGuard aGuard( LockMutex::get() ); std::vector<InternalStreamLock> &rLockList = LockList::get(); - for( std::vector<InternalStreamLock>::const_iterator i = rLockList.begin(); - i != rLockList.end(); ) + for( const auto& rLock : rLockList ) { - if( aItem.isIdenticalTo( i->m_aItem ) ) + if( aItem.isIdenticalTo( rLock.m_aItem ) ) { - bool bDenyByOptions = false; - StreamMode nLockMode = i->m_pStream->GetStreamMode(); + StreamMode nLockMode = rLock.m_pStream->GetStreamMode(); StreamMode nNewMode = pStream->GetStreamMode(); - - if( nLockMode & StreamMode::SHARE_DENYALL ) - bDenyByOptions = true; - else if( ( nLockMode & StreamMode::SHARE_DENYWRITE ) && - ( nNewMode & StreamMode::WRITE ) ) - bDenyByOptions = true; - else if( ( nLockMode &StreamMode::SHARE_DENYREAD ) && - ( nNewMode & StreamMode::READ ) ) - bDenyByOptions = true; + bool bDenyByOptions = (nLockMode & StreamMode::SHARE_DENYALL) || + ( (nLockMode & StreamMode::SHARE_DENYWRITE) && (nNewMode & StreamMode::WRITE) ) || + ( (nLockMode & StreamMode::SHARE_DENYREAD) && (nNewMode & StreamMode::READ) ); if( bDenyByOptions ) { - if( i->m_nStartPos == 0 && i->m_nEndPos == 0 ) // whole file is already locked + if( rLock.m_nStartPos == 0 && rLock.m_nEndPos == 0 ) // whole file is already locked return false; if( nStart == 0 && nEnd == 0) // cannot lock whole file return false; - if( ( nStart < i->m_nStartPos && nEnd > i->m_nStartPos ) || - ( nStart < i->m_nEndPos && nEnd > i->m_nEndPos ) ) + if( ( nStart < rLock.m_nStartPos && nEnd > rLock.m_nStartPos ) || + ( nStart < rLock.m_nEndPos && nEnd > rLock.m_nEndPos ) ) return false; } } @@ -149,20 +142,12 @@ void unlockFile( sal_uInt64 const nStart, sal_uInt64 const nEnd, SvFileStream co { osl::MutexGuard aGuard( LockMutex::get() ); std::vector<InternalStreamLock> &rLockList = LockList::get(); - for( std::vector<InternalStreamLock>::iterator i = rLockList.begin(); - i != rLockList.end(); ) - { - if ( i->m_pStream == pStream - && ( ( nStart == 0 && nEnd == 0 ) - || ( i->m_nStartPos == nStart && i->m_nEndPos == nEnd ) ) ) - { - i = rLockList.erase(i); - } - else - { - ++i; - } - } + rLockList.erase(std::remove_if(rLockList.begin(), rLockList.end(), + [&pStream, &nStart, &nEnd](const InternalStreamLock& rLock) { + return rLock.m_pStream == pStream + && ((nStart == 0 && nEnd == 0) + || (rLock.m_nStartPos == nStart && rLock.m_nEndPos == nEnd)); + }), rLockList.end()); } } |