diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2019-02-15 00:08:43 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-02-15 12:21:28 +0100 |
commit | 9d7620613d3ea2feb45a7ff57c4d2544bb1c6fe6 (patch) | |
tree | 20e56cfbe9a0bc07974fb14861556da74f3ecddc /package | |
parent | 177747c44557489760cc00473daecacd99995427 (diff) |
Simplify containers iterations in oox, opencl, package
Use range-based loop or replace with STL functions
Change-Id: I91405920d91383bc6cf13b9497d262b1f6f0a84d
Reviewed-on: https://gerrit.libreoffice.org/67848
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'package')
-rw-r--r-- | package/source/xstor/ohierarchyholder.cxx | 16 | ||||
-rw-r--r-- | package/source/xstor/owriteablestream.cxx | 9 | ||||
-rw-r--r-- | package/source/xstor/xstorage.cxx | 196 | ||||
-rw-r--r-- | package/source/zipapi/ZipFile.cxx | 26 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackage.cxx | 11 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageFolder.cxx | 33 | ||||
-rw-r--r-- | package/source/zippackage/zipfileaccess.cxx | 27 |
7 files changed, 136 insertions, 182 deletions
diff --git a/package/source/xstor/ohierarchyholder.cxx b/package/source/xstor/ohierarchyholder.cxx index 800cfdf7ce1f..26b63f806eae 100644 --- a/package/source/xstor/ohierarchyholder.cxx +++ b/package/source/xstor/ohierarchyholder.cxx @@ -264,18 +264,10 @@ void SAL_CALL OHierarchyElement_Impl::disposing( const lang::EventObject& Source ::osl::ClearableMutexGuard aGuard( m_aMutex ); uno::Reference< embed::XExtendedStorageStream > xStream( Source.Source, uno::UNO_QUERY ); - for ( OWeakStorRefList_Impl::iterator pStorageIter = m_aOpenStreams.begin(); - pStorageIter != m_aOpenStreams.end(); ) - { - if ( !pStorageIter->get().is() || pStorageIter->get() == xStream ) - { - pStorageIter = m_aOpenStreams.erase(pStorageIter); - } - else - { - ++pStorageIter; - } - } + m_aOpenStreams.erase(std::remove_if(m_aOpenStreams.begin(), m_aOpenStreams.end(), + [&xStream](const OWeakStorRefList_Impl::value_type& rxStorage) { + return !rxStorage.get().is() || rxStorage.get() == xStream; }), + m_aOpenStreams.end()); aGuard.clear(); diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx index f81c3af1c5eb..63cdbad804ed 100644 --- a/package/source/xstor/owriteablestream.cxx +++ b/package/source/xstor/owriteablestream.cxx @@ -481,13 +481,12 @@ void OWriteStream_Impl::DisposeWrappers() if ( !m_aInputStreamsVector.empty() ) { - for ( InputStreamsVector_Impl::iterator pStreamIter = m_aInputStreamsVector.begin(); - pStreamIter != m_aInputStreamsVector.end(); ++pStreamIter ) + for ( auto& pStream : m_aInputStreamsVector ) { - if ( *pStreamIter ) + if ( pStream ) { - (*pStreamIter)->InternalDispose(); - (*pStreamIter) = nullptr; + pStream->InternalDispose(); + pStream = nullptr; } } diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx index a07d06cbaa20..2dc532324084 100644 --- a/package/source/xstor/xstorage.cxx +++ b/package/source/xstor/xstorage.cxx @@ -303,13 +303,12 @@ OStorage_Impl::~OStorage_Impl() } else if ( !m_aReadOnlyWrapVector.empty() ) { - for ( StorageHoldersType::iterator pStorageIter = m_aReadOnlyWrapVector.begin(); - pStorageIter != m_aReadOnlyWrapVector.end(); ++pStorageIter ) + for ( auto& rStorage : m_aReadOnlyWrapVector ) { - uno::Reference< embed::XStorage > xTmp = pStorageIter->m_xWeakRef; + uno::Reference< embed::XStorage > xTmp = rStorage.m_xWeakRef; if ( xTmp.is() ) try { - pStorageIter->m_pPointer->InternalDispose( false ); + rStorage.m_pPointer->InternalDispose( false ); } catch( const uno::Exception& rException ) { SAL_INFO("package.xstor", "Quiet exception: " << rException); @@ -652,11 +651,10 @@ void OStorage_Impl::CopyToStorage( const uno::Reference< embed::XStorage >& xDes if ( !m_xPackageFolder.is() ) throw embed::InvalidStorageException( THROW_WHERE ); - for ( SotElementVector_Impl::iterator pElementIter = m_aChildrenVector.begin(); - pElementIter != m_aChildrenVector.end(); ++pElementIter ) + for ( auto& pElement : m_aChildrenVector ) { - if ( !(*pElementIter)->m_bIsRemoved ) - CopyStorageElement( *pElementIter, xDest, (*pElementIter)->m_aName, bDirect ); + if ( !pElement->m_bIsRemoved ) + CopyStorageElement( pElement, xDest, pElement->m_aName, bDirect ); } // move storage properties to the destination one ( means changeable properties ) @@ -1007,19 +1005,17 @@ void OStorage_Impl::Commit() xNewPackageFolder = m_xPackageFolder; // remove replaced removed elements - for ( SotElementVector_Impl::iterator pDeletedIter = m_aDeletedVector.begin(); - pDeletedIter != m_aDeletedVector.end(); - ++pDeletedIter ) + for ( auto& pDeleted : m_aDeletedVector ) { - if ( m_nStorageType == embed::StorageFormats::OFOPXML && !(*pDeletedIter)->m_bIsStorage ) - RemoveStreamRelInfo( (*pDeletedIter)->m_aOriginalName ); + if ( m_nStorageType == embed::StorageFormats::OFOPXML && !pDeleted->m_bIsStorage ) + RemoveStreamRelInfo( pDeleted->m_aOriginalName ); // the removed elements are not in new temporary storage if ( m_bCommited || m_bIsRoot ) - xNewPackageFolder->removeByName( (*pDeletedIter)->m_aOriginalName ); - delete *pDeletedIter; - *pDeletedIter = nullptr; + xNewPackageFolder->removeByName( pDeleted->m_aOriginalName ); + delete pDeleted; + pDeleted = nullptr; } m_aDeletedVector.clear(); @@ -1047,116 +1043,116 @@ void OStorage_Impl::Commit() } // there should be no more deleted elements - for ( pElementIter = m_aChildrenVector.begin(); pElementIter != m_aChildrenVector.end(); ++pElementIter ) + for ( auto& pElement : m_aChildrenVector ) { // if it is a 'duplicate commit' inserted elements must be really inserted to package later // since thay can conflict with renamed elements - if ( !(*pElementIter)->m_bIsInserted ) + if ( !pElement->m_bIsInserted ) { // for now stream is opened in direct mode that means that in case // storage is committed all the streams from it are committed in current state. // following two steps are separated to allow easily implement transacted mode // for streams if we need it in future. // Only hierarchical access uses transacted streams currently - if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_xStream - && !(*pElementIter)->m_xStream->IsTransacted() ) - (*pElementIter)->m_xStream->Commit(); + if ( !pElement->m_bIsStorage && pElement->m_xStream + && !pElement->m_xStream->IsTransacted() ) + pElement->m_xStream->Commit(); // if the storage was not open, there is no need to commit it ??? // the storage should be checked that it is committed - if ((*pElementIter)->m_bIsStorage && (*pElementIter)->m_xStorage && (*pElementIter)->m_xStorage->m_bCommited) + if (pElement->m_bIsStorage && pElement->m_xStorage && pElement->m_xStorage->m_bCommited) { // it's temporary PackageFolder should be inserted instead of current one // also the new copy of PackageFolder should be used by the children storages // the renamed elements are not in new temporary storage if ( m_bCommited || m_bIsRoot ) - xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName ); + xNewPackageFolder->removeByName( pElement->m_aOriginalName ); - (*pElementIter)->m_xStorage->InsertIntoPackageFolder((*pElementIter)->m_aName, xNewPackageFolder); + pElement->m_xStorage->InsertIntoPackageFolder(pElement->m_aName, xNewPackageFolder); } - else if (!(*pElementIter)->m_bIsStorage && (*pElementIter)->m_xStream && (*pElementIter)->m_xStream->m_bFlushed) + else if (!pElement->m_bIsStorage && pElement->m_xStream && pElement->m_xStream->m_bFlushed) { if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - CommitStreamRelInfo( *pElementIter ); + CommitStreamRelInfo( pElement ); // the renamed elements are not in new temporary storage if ( m_bCommited || m_bIsRoot ) - xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName ); + xNewPackageFolder->removeByName( pElement->m_aOriginalName ); - (*pElementIter)->m_xStream->InsertIntoPackageFolder((*pElementIter)->m_aName, xNewPackageFolder); + pElement->m_xStream->InsertIntoPackageFolder(pElement->m_aName, xNewPackageFolder); } else if ( !m_bCommited && !m_bIsRoot ) { // the element must be just copied to the new temporary package folder // the connection with the original package should not be lost just because // the element is still referred by the folder in the original hierarchy - uno::Any aPackageElement = m_xPackageFolder->getByName( (*pElementIter)->m_aOriginalName ); - xNewPackageFolder->insertByName( (*pElementIter)->m_aName, aPackageElement ); + uno::Any aPackageElement = m_xPackageFolder->getByName( pElement->m_aOriginalName ); + xNewPackageFolder->insertByName( pElement->m_aName, aPackageElement ); } - else if ( (*pElementIter)->m_aName != (*pElementIter)->m_aOriginalName ) + else if ( pElement->m_aName != pElement->m_aOriginalName ) { // this is the case when xNewPackageFolder refers to m_xPackageFolder // in case the name was changed and it is not a changed storage - rename the element - uno::Any aPackageElement = xNewPackageFolder->getByName( (*pElementIter)->m_aOriginalName ); - xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName ); - xNewPackageFolder->insertByName( (*pElementIter)->m_aName, aPackageElement ); + uno::Any aPackageElement = xNewPackageFolder->getByName( pElement->m_aOriginalName ); + xNewPackageFolder->removeByName( pElement->m_aOriginalName ); + xNewPackageFolder->insertByName( pElement->m_aName, aPackageElement ); - if ( m_nStorageType == embed::StorageFormats::OFOPXML && !(*pElementIter)->m_bIsStorage ) + if ( m_nStorageType == embed::StorageFormats::OFOPXML && !pElement->m_bIsStorage ) { - if (!(*pElementIter)->m_xStream) + if (!pElement->m_xStream) { - OpenSubStream( *pElementIter ); - if (!(*pElementIter)->m_xStream) + OpenSubStream( pElement ); + if (!pElement->m_xStream) throw uno::RuntimeException( THROW_WHERE ); } - CommitStreamRelInfo( *pElementIter ); + CommitStreamRelInfo( pElement ); } } - (*pElementIter)->m_aOriginalName = (*pElementIter)->m_aName; + pElement->m_aOriginalName = pElement->m_aName; } } - for ( pElementIter = m_aChildrenVector.begin(); pElementIter != m_aChildrenVector.end(); ++pElementIter ) + for ( auto& pElement : m_aChildrenVector ) { // now inserted elements can be inserted to the package - if ( (*pElementIter)->m_bIsInserted ) + if ( pElement->m_bIsInserted ) { - (*pElementIter)->m_aOriginalName = (*pElementIter)->m_aName; + pElement->m_aOriginalName = pElement->m_aName; - if ( (*pElementIter)->m_bIsStorage ) + if ( pElement->m_bIsStorage ) { - if ((*pElementIter)->m_xStorage->m_bCommited) + if (pElement->m_xStorage->m_bCommited) { - OSL_ENSURE((*pElementIter)->m_xStorage, "An inserted storage is incomplete!"); - if (!(*pElementIter)->m_xStorage) + OSL_ENSURE(pElement->m_xStorage, "An inserted storage is incomplete!"); + if (!pElement->m_xStorage) throw uno::RuntimeException( THROW_WHERE ); - (*pElementIter)->m_xStorage->InsertIntoPackageFolder((*pElementIter)->m_aName, xNewPackageFolder); + pElement->m_xStorage->InsertIntoPackageFolder(pElement->m_aName, xNewPackageFolder); - (*pElementIter)->m_bIsInserted = false; + pElement->m_bIsInserted = false; } } else { - OSL_ENSURE((*pElementIter)->m_xStream, "An inserted stream is incomplete!"); - if (!(*pElementIter)->m_xStream) + OSL_ENSURE(pElement->m_xStream, "An inserted stream is incomplete!"); + if (!pElement->m_xStream) throw uno::RuntimeException( THROW_WHERE ); - if (!(*pElementIter)->m_xStream->IsTransacted()) - (*pElementIter)->m_xStream->Commit(); + if (!pElement->m_xStream->IsTransacted()) + pElement->m_xStream->Commit(); - if ((*pElementIter)->m_xStream->m_bFlushed) + if (pElement->m_xStream->m_bFlushed) { if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - CommitStreamRelInfo( *pElementIter ); + CommitStreamRelInfo( pElement ); - (*pElementIter)->m_xStream->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder ); + pElement->m_xStream->InsertIntoPackageFolder( pElement->m_aName, xNewPackageFolder ); - (*pElementIter)->m_bIsInserted = false; + pElement->m_bIsInserted = false; } } } @@ -1235,16 +1231,14 @@ void OStorage_Impl::Revert() } // return replaced removed elements - for ( SotElementVector_Impl::iterator pDeletedIter = m_aDeletedVector.begin(); - pDeletedIter != m_aDeletedVector.end(); - ++pDeletedIter ) + for ( auto& pDeleted : m_aDeletedVector ) { - m_aChildrenVector.push_back( *pDeletedIter ); + m_aChildrenVector.push_back( pDeleted ); - ClearElement( *pDeletedIter ); + ClearElement( pDeleted ); - (*pDeletedIter)->m_aName = (*pDeletedIter)->m_aOriginalName; - (*pDeletedIter)->m_bIsRemoved = false; + pDeleted->m_aName = pDeleted->m_aOriginalName; + pDeleted->m_bIsRemoved = false; } m_aDeletedVector.clear(); @@ -1293,12 +1287,10 @@ SotElement_Impl* OStorage_Impl::FindElement( const OUString& rName ) ReadContents(); - for ( SotElementVector_Impl::iterator pElementIter = m_aChildrenVector.begin(); - pElementIter != m_aChildrenVector.end(); ++pElementIter ) - { - if ( (*pElementIter)->m_aName == rName && !(*pElementIter)->m_bIsRemoved ) - return *pElementIter; - } + auto pElementIter = std::find_if(m_aChildrenVector.begin(), m_aChildrenVector.end(), + [&rName](const SotElement_Impl* pElement) { return pElement->m_aName == rName && !pElement->m_bIsRemoved; }); + if (pElementIter != m_aChildrenVector.end()) + return *pElementIter; return nullptr; } @@ -1414,16 +1406,15 @@ SotElement_Impl* OStorage_Impl::InsertElement( const OUString& aName, bool bIsSt SotElement_Impl* pDeletedElm = nullptr; - for ( SotElementVector_Impl::iterator pElementIter = m_aChildrenVector.begin(); - pElementIter != m_aChildrenVector.end(); ++pElementIter ) + for ( const auto& pElement : m_aChildrenVector ) { - if ( (*pElementIter)->m_aName == aName ) + if ( pElement->m_aName == aName ) { - SAL_WARN_IF( !(*pElementIter)->m_bIsRemoved, "package.xstor", "Try to insert an element instead of existing one!" ); - if ( (*pElementIter)->m_bIsRemoved ) + SAL_WARN_IF( !pElement->m_bIsRemoved, "package.xstor", "Try to insert an element instead of existing one!" ); + if ( pElement->m_bIsRemoved ) { - SAL_WARN_IF( (*pElementIter)->m_bIsInserted, "package.xstor", "Inserted elements must be deleted immediately!" ); - pDeletedElm = *pElementIter; + SAL_WARN_IF( pElement->m_bIsInserted, "package.xstor", "Inserted elements must be deleted immediately!" ); + pDeletedElm = pElement; break; } } @@ -1500,11 +1491,10 @@ uno::Sequence< OUString > OStorage_Impl::GetElementNames() uno::Sequence< OUString > aElementNames( nSize ); sal_uInt32 nInd = 0; - for ( SotElementVector_Impl::iterator pElementIter = m_aChildrenVector.begin(); - pElementIter != m_aChildrenVector.end(); ++pElementIter ) + for ( const auto& pElement : m_aChildrenVector ) { - if ( !(*pElementIter)->m_bIsRemoved ) - aElementNames[nInd++] = (*pElementIter)->m_aName; + if ( !pElement->m_bIsRemoved ) + aElementNames[nInd++] = pElement->m_aName; } aElementNames.realloc( nInd ); @@ -1847,10 +1837,9 @@ void OStorage::InternalDispose( bool bNotifyImpl ) // deregister m_pData->m_pSubElDispListener and dispose all of them if ( !m_pData->m_aOpenSubComponentsVector.empty() ) { - for ( WeakComponentVector::iterator pCompIter = m_pData->m_aOpenSubComponentsVector.begin(); - pCompIter != m_pData->m_aOpenSubComponentsVector.end(); ++pCompIter ) + for ( auto& pComp : m_pData->m_aOpenSubComponentsVector ) { - uno::Reference< lang::XComponent > xTmp = *pCompIter; + uno::Reference< lang::XComponent > xTmp = pComp; if ( xTmp.is() ) { xTmp->removeEventListener( uno::Reference< lang::XEventListener >( @@ -1898,17 +1887,12 @@ void OStorage::ChildIsDisposed( const uno::Reference< uno::XInterface >& xChild // this method must not contain any locking // the locking is done in the listener - for ( WeakComponentVector::iterator pCompIter = m_pData->m_aOpenSubComponentsVector.begin(); - pCompIter != m_pData->m_aOpenSubComponentsVector.end(); ) - { - uno::Reference< lang::XComponent > xTmp = *pCompIter; - if ( !xTmp.is() || xTmp == xChild ) - { - pCompIter = m_pData->m_aOpenSubComponentsVector.erase(pCompIter); - } - else - ++pCompIter; - } + auto& rVec = m_pData->m_aOpenSubComponentsVector; + rVec.erase(std::remove_if(rVec.begin(), rVec.end(), + [&xChild](const uno::Reference<lang::XComponent>& xTmp) { + return !xTmp.is() || xTmp == xChild; + }), + rVec.end()); } void OStorage::BroadcastModifiedIfNecessary() @@ -2399,12 +2383,8 @@ uno::Reference< embed::XStorage > SAL_CALL OStorage::openStorageElement( if ( nStorageMode & embed::ElementModes::TRUNCATE ) { - for ( SotElementVector_Impl::iterator pElementIter = pElement->m_xStorage->m_aChildrenVector.begin(); - pElementIter != pElement->m_xStorage->m_aChildrenVector.end(); ) + for ( SotElement_Impl* pElementToDel : pElement->m_xStorage->m_aChildrenVector ) { - SotElement_Impl* pElementToDel = *pElementIter; - ++pElementIter; - m_pImpl->RemoveElement( pElementToDel ); } } @@ -3616,15 +3596,13 @@ void SAL_CALL OStorage::revert() throw lang::DisposedException( THROW_WHERE ); } - for ( SotElementVector_Impl::iterator pElementIter = m_pImpl->m_aChildrenVector.begin(); - pElementIter != m_pImpl->m_aChildrenVector.end(); ++pElementIter ) - { - if ( ((*pElementIter)->m_xStorage - && ( (*pElementIter)->m_xStorage->m_pAntiImpl || !(*pElementIter)->m_xStorage->m_aReadOnlyWrapVector.empty() )) - || ((*pElementIter)->m_xStream - && ( (*pElementIter)->m_xStream->m_pAntiImpl || !(*pElementIter)->m_xStream->m_aInputStreamsVector.empty()) ) ) - throw io::IOException( THROW_WHERE ); // TODO: access denied - } + bool bThrow = std::any_of(m_pImpl->m_aChildrenVector.begin(), m_pImpl->m_aChildrenVector.end(), [](const SotElement_Impl* pElement) { + return (pElement->m_xStorage + && (pElement->m_xStorage->m_pAntiImpl || !pElement->m_xStorage->m_aReadOnlyWrapVector.empty())) + || (pElement->m_xStream + && (pElement->m_xStream->m_pAntiImpl || !pElement->m_xStream->m_aInputStreamsVector.empty())); }); + if (bThrow) + throw io::IOException( THROW_WHERE ); // TODO: access denied if ( m_pData->m_bReadOnlyWrap || !m_pImpl->m_bListCreated ) return; // nothing to do diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx index 4f3092e56755..24bcab959960 100644 --- a/package/source/zipapi/ZipFile.cxx +++ b/package/source/zipapi/ZipFile.cxx @@ -1086,18 +1086,18 @@ void ZipFile::recover() nCompressedSize = nCompressedSize32; nSize = nSize32; - for( EntryHash::iterator aIter = aEntries.begin(); aIter != aEntries.end(); ++aIter ) + for( auto& rEntry : aEntries ) { - ZipEntry aTmp = (*aIter).second; + ZipEntry aTmp = rEntry.second; // this is a broken package, accept this block not only for DEFLATED streams - if( (*aIter).second.nFlag & 8 ) + if( rEntry.second.nFlag & 8 ) { sal_Int64 nStreamOffset = nGenPos + nPos - nCompressedSize; - if ( nStreamOffset == (*aIter).second.nOffset && nCompressedSize > (*aIter).second.nCompressedSize ) + if ( nStreamOffset == rEntry.second.nOffset && nCompressedSize > rEntry.second.nCompressedSize ) { // only DEFLATED blocks need to be checked - bool bAcceptBlock = ( (*aIter).second.nMethod == STORED && nCompressedSize == nSize ); + bool bAcceptBlock = ( rEntry.second.nMethod == STORED && nCompressedSize == nSize ); if ( !bAcceptBlock ) { @@ -1109,19 +1109,19 @@ void ZipFile::recover() if ( bAcceptBlock ) { - (*aIter).second.nCrc = nCRC32; - (*aIter).second.nCompressedSize = nCompressedSize; - (*aIter).second.nSize = nSize; + rEntry.second.nCrc = nCRC32; + rEntry.second.nCompressedSize = nCompressedSize; + rEntry.second.nSize = nSize; } } #if 0 // for now ignore clearly broken streams - else if( !(*aIter).second.nCompressedSize ) + else if( !rEntry.second.nCompressedSize ) { - (*aIter).second.nCrc = nCRC32; - sal_Int32 nRealStreamSize = nGenPos + nPos - (*aIter).second.nOffset; - (*aIter).second.nCompressedSize = nGenPos + nPos - (*aIter).second.nOffset; - (*aIter).second.nSize = nSize; + rEntry.second.nCrc = nCRC32; + sal_Int32 nRealStreamSize = nGenPos + nPos - rEntry.second.nOffset; + rEntry.second.nCompressedSize = nRealStreamSize; + rEntry.second.nSize = nSize; } #endif } diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index b22b83ec7be0..42c78532a2db 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -1103,20 +1103,17 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno: uno::Sequence< beans::StringPair > aOverridesSequence(aManList.size()); sal_Int32 nOverSeqLength = 0; - for ( vector< uno::Sequence< beans::PropertyValue > >::const_iterator aIter = aManList.begin(), - aEnd = aManList.end(); - aIter != aEnd; - ++aIter) + for (const auto& rMan : aManList) { OUString aPath; OUString aType; - OSL_ENSURE( ( *aIter )[PKG_MNFST_MEDIATYPE].Name == "MediaType" && ( *aIter )[PKG_MNFST_FULLPATH].Name == "FullPath", + OSL_ENSURE( rMan[PKG_MNFST_MEDIATYPE].Name == "MediaType" && rMan[PKG_MNFST_FULLPATH].Name == "FullPath", "The mediatype sequence format is wrong!" ); - ( *aIter )[PKG_MNFST_MEDIATYPE].Value >>= aType; + rMan[PKG_MNFST_MEDIATYPE].Value >>= aType; if ( !aType.isEmpty() ) { // only nonempty type makes sense here - ( *aIter )[PKG_MNFST_FULLPATH].Value >>= aPath; + rMan[PKG_MNFST_FULLPATH].Value >>= aPath; //FIXME: For now we have no way of differentiating defaults from others. aOverridesSequence[nOverSeqLength].First = "/" + aPath; aOverridesSequence[nOverSeqLength].Second = aType; diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx index 54ec4e40bbee..c42fdef45ac8 100644 --- a/package/source/zippackage/ZipPackageFolder.cxx +++ b/package/source/zippackage/ZipPackageFolder.cxx @@ -27,6 +27,7 @@ #include "ZipPackageFolderEnumeration.hxx" #include <com/sun/star/packages/zip/ZipConstants.hpp> #include <com/sun/star/embed/StorageFormats.hpp> +#include <comphelper/sequence.hxx> #include <cppuhelper/supportsservice.hxx> #include <cppuhelper/typeprovider.hxx> #include <osl/diagnose.h> @@ -81,12 +82,9 @@ bool ZipPackageFolder::LookForUnexpectedODF12Streams( const OUString& aPath ) { bool bHasUnexpected = false; - for ( ContentHash::const_iterator aCI = maContents.begin(), aEnd = maContents.end(); - !bHasUnexpected && aCI != aEnd; - ++aCI) + for (const auto& [rShortName, rxInfo] : maContents) { - const OUString &rShortName = (*aCI).first; - const ZipContentInfo &rInfo = *(*aCI).second; + const ZipContentInfo &rInfo = *rxInfo; if ( rInfo.bFolder ) { @@ -125,6 +123,9 @@ bool ZipPackageFolder::LookForUnexpectedODF12Streams( const OUString& aPath ) } } } + + if (bHasUnexpected) + break; } return bHasUnexpected; @@ -138,12 +139,9 @@ void ZipPackageFolder::setChildStreamsTypeByExtension( const beans::StringPair& else aExt = "." + aPair.First; - for ( ContentHash::const_iterator aCI = maContents.begin(), aEnd = maContents.end(); - aCI != aEnd; - ++aCI) + for (const auto& [rShortName, rxInfo] : maContents) { - const OUString &rShortName = (*aCI).first; - const ZipContentInfo &rInfo = *(*aCI).second; + const ZipContentInfo &rInfo = *rxInfo; if ( rInfo.bFolder ) rInfo.pFolder->setChildStreamsTypeByExtension( aPair ); @@ -229,13 +227,7 @@ uno::Any SAL_CALL ZipPackageFolder::getByName( const OUString& aName ) } uno::Sequence< OUString > SAL_CALL ZipPackageFolder::getElementNames( ) { - sal_uInt32 i=0, nSize = maContents.size(); - uno::Sequence < OUString > aSequence ( nSize ); - for ( ContentHash::const_iterator aIterator = maContents.begin(), aEnd = maContents.end(); - aIterator != aEnd; - ++i, ++aIterator) - aSequence[i] = (*aIterator).first; - return aSequence; + return comphelper::mapKeysToSequence(maContents); } sal_Bool SAL_CALL ZipPackageFolder::hasByName( const OUString& aName ) { @@ -335,12 +327,9 @@ void ZipPackageFolder::saveContents( } } - for ( ContentHash::const_iterator aCI = maContents.begin(), aEnd = maContents.end(); - aCI != aEnd; - ++aCI) + for (const auto& [rShortName, rxInfo] : maContents) { - const OUString &rShortName = (*aCI).first; - const ZipContentInfo &rInfo = *(*aCI).second; + const ZipContentInfo &rInfo = *rxInfo; if ( !bMimeTypeStreamStored || rShortName != aMimeTypeStreamName ) { diff --git a/package/source/zippackage/zipfileaccess.cxx b/package/source/zippackage/zipfileaccess.cxx index b9167a9f3a2e..d6cd52849735 100644 --- a/package/source/zippackage/zipfileaccess.cxx +++ b/package/source/zippackage/zipfileaccess.cxx @@ -309,7 +309,7 @@ uno::Sequence< OUString > SAL_CALL OZipFileAccess::getElementNames() uno::Sequence< OUString > aNames( m_pZipFile->GetEntryHash().size() ); sal_Int32 nLen = 0; - for ( EntryHash::iterator aIter = m_pZipFile->GetEntryHash().begin(); aIter != m_pZipFile->GetEntryHash().end(); ++aIter ) + for ( const auto& rEntry : m_pZipFile->GetEntryHash() ) { if ( aNames.getLength() < ++nLen ) { @@ -317,7 +317,7 @@ uno::Sequence< OUString > SAL_CALL OZipFileAccess::getElementNames() aNames.realloc( nLen ); } - aNames[nLen-1] = (*aIter).second.sPath; + aNames[nLen-1] = rEntry.second.sPath; } if ( aNames.getLength() != nLen ) @@ -384,19 +384,18 @@ uno::Reference< io::XInputStream > SAL_CALL OZipFileAccess::getStreamByPattern( // Code to compare strings by patterns uno::Sequence< OUString > aPattern = GetPatternsFromString_Impl( aPatternString ); - for ( EntryHash::iterator aIter = m_pZipFile->GetEntryHash().begin(); aIter != m_pZipFile->GetEntryHash().end(); ++aIter ) + auto aIter = std::find_if(m_pZipFile->GetEntryHash().begin(), m_pZipFile->GetEntryHash().end(), + [&aPattern](const EntryHash::value_type& rEntry) { return StringGoodForPattern_Impl(rEntry.second.sPath, aPattern); }); + if (aIter != m_pZipFile->GetEntryHash().end()) { - if ( StringGoodForPattern_Impl( (*aIter).second.sPath, aPattern ) ) - { - uno::Reference< io::XInputStream > xEntryStream( m_pZipFile->getDataStream( (*aIter).second, - ::rtl::Reference< EncryptionData >(), - false, - m_aMutexHolder ) ); - - if ( !xEntryStream.is() ) - throw uno::RuntimeException(THROW_WHERE ); - return xEntryStream; - } + uno::Reference< io::XInputStream > xEntryStream( m_pZipFile->getDataStream( (*aIter).second, + ::rtl::Reference< EncryptionData >(), + false, + m_aMutexHolder ) ); + + if ( !xEntryStream.is() ) + throw uno::RuntimeException(THROW_WHERE ); + return xEntryStream; } throw container::NoSuchElementException(THROW_WHERE ); |