Replace some lists by vectors in xstorage (part2)

Change-Id: Icb10605f9ac75aa5b00668a5088be8ef6e1414da
Reviewed-on: https://gerrit.libreoffice.org/41543
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Julien Nabet
2017-08-24 23:27:57 +02:00
committed by Noel Grandin
parent a726c69ffe
commit 9245ce93b0
2 changed files with 51 additions and 57 deletions

View File

@@ -321,11 +321,11 @@ OStorage_Impl::~OStorage_Impl()
m_pParent = nullptr; m_pParent = nullptr;
} }
std::for_each(m_aChildrenList.begin(), m_aChildrenList.end(), std::default_delete<SotElement_Impl>()); std::for_each(m_aChildrenVector.begin(), m_aChildrenVector.end(), std::default_delete<SotElement_Impl>());
m_aChildrenList.clear(); m_aChildrenVector.clear();
std::for_each(m_aDeletedList.begin(), m_aDeletedList.end(), std::default_delete<SotElement_Impl>()); std::for_each(m_aDeletedVector.begin(), m_aDeletedVector.end(), std::default_delete<SotElement_Impl>());
m_aDeletedList.clear(); m_aDeletedVector.clear();
if ( m_nStorageType == embed::StorageFormats::OFOPXML && m_pRelStorElement ) if ( m_nStorageType == embed::StorageFormats::OFOPXML && m_pRelStorElement )
{ {
@@ -482,12 +482,12 @@ void OStorage_Impl::OpenOwnPackage()
throw embed::InvalidStorageException( THROW_WHERE ); throw embed::InvalidStorageException( THROW_WHERE );
} }
SotElementList_Impl& OStorage_Impl::GetChildrenList() SotElementVector_Impl& OStorage_Impl::GetChildrenVector()
{ {
::osl::MutexGuard aGuard( m_xMutex->GetMutex() ); ::osl::MutexGuard aGuard( m_xMutex->GetMutex() );
ReadContents(); ReadContents();
return m_aChildrenList; return m_aChildrenVector;
} }
void OStorage_Impl::GetStorageProperties() void OStorage_Impl::GetStorageProperties()
@@ -609,7 +609,7 @@ void OStorage_Impl::ReadContents()
pNewElement->m_bIsRemoved = true; pNewElement->m_bIsRemoved = true;
} }
m_aChildrenList.push_back( pNewElement ); m_aChildrenVector.push_back( pNewElement );
} }
} }
catch( const container::NoSuchElementException& rNoSuchElementException ) catch( const container::NoSuchElementException& rNoSuchElementException )
@@ -649,8 +649,8 @@ void OStorage_Impl::CopyToStorage( const uno::Reference< embed::XStorage >& xDes
if ( !m_xPackageFolder.is() ) if ( !m_xPackageFolder.is() )
throw embed::InvalidStorageException( THROW_WHERE ); throw embed::InvalidStorageException( THROW_WHERE );
for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); for ( SotElementVector_Impl::iterator pElementIter = m_aChildrenVector.begin();
pElementIter != m_aChildrenList.end(); ++pElementIter ) pElementIter != m_aChildrenVector.end(); ++pElementIter )
{ {
if ( !(*pElementIter)->m_bIsRemoved ) if ( !(*pElementIter)->m_bIsRemoved )
CopyStorageElement( *pElementIter, xDest, (*pElementIter)->m_aName, bDirect ); CopyStorageElement( *pElementIter, xDest, (*pElementIter)->m_aName, bDirect );
@@ -1003,8 +1003,8 @@ void OStorage_Impl::Commit()
xNewPackageFolder = m_xPackageFolder; xNewPackageFolder = m_xPackageFolder;
// remove replaced removed elements // remove replaced removed elements
for ( SotElementList_Impl::iterator pDeletedIter = m_aDeletedList.begin(); for ( SotElementVector_Impl::iterator pDeletedIter = m_aDeletedVector.begin();
pDeletedIter != m_aDeletedList.end(); pDeletedIter != m_aDeletedVector.end();
++pDeletedIter ) ++pDeletedIter )
{ {
@@ -1017,11 +1017,11 @@ void OStorage_Impl::Commit()
delete *pDeletedIter; delete *pDeletedIter;
*pDeletedIter = nullptr; *pDeletedIter = nullptr;
} }
m_aDeletedList.clear(); m_aDeletedVector.clear();
// remove removed elements // remove removed elements
SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); SotElementVector_Impl::iterator pElementIter = m_aChildrenVector.begin();
while ( pElementIter != m_aChildrenList.end() ) while ( pElementIter != m_aChildrenVector.end() )
{ {
// renamed and inserted elements must be really inserted to package later // renamed and inserted elements must be really inserted to package later
// since thay can conflict with removed elements // since thay can conflict with removed elements
@@ -1035,19 +1035,15 @@ void OStorage_Impl::Commit()
if ( m_bCommited || m_bIsRoot ) if ( m_bCommited || m_bIsRoot )
xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName ); xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
SotElement_Impl* pToDelete = *pElementIter; delete *pElementIter;
pElementIter = m_aChildrenVector.erase(pElementIter);
++pElementIter; // to let the iterator be valid it should be increased before removing
m_aChildrenList.remove( pToDelete );
delete pToDelete;
} }
else else
++pElementIter; ++pElementIter;
} }
// there should be no more deleted elements // there should be no more deleted elements
for ( pElementIter = m_aChildrenList.begin(); pElementIter != m_aChildrenList.end(); ++pElementIter ) for ( pElementIter = m_aChildrenVector.begin(); pElementIter != m_aChildrenVector.end(); ++pElementIter )
{ {
// if it is a 'duplicate commit' inserted elements must be really inserted to package later // if it is a 'duplicate commit' inserted elements must be really inserted to package later
// since thay can conflict with renamed elements // since thay can conflict with renamed elements
@@ -1120,7 +1116,7 @@ void OStorage_Impl::Commit()
} }
} }
for ( pElementIter = m_aChildrenList.begin(); pElementIter != m_aChildrenList.end(); ++pElementIter ) for ( pElementIter = m_aChildrenVector.begin(); pElementIter != m_aChildrenVector.end(); ++pElementIter )
{ {
// now inserted elements can be inserted to the package // now inserted elements can be inserted to the package
if ( (*pElementIter)->m_bIsInserted ) if ( (*pElementIter)->m_bIsInserted )
@@ -1215,17 +1211,13 @@ void OStorage_Impl::Revert()
// all the children must be removed // all the children must be removed
// they will be created later on demand // they will be created later on demand
SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); SotElementVector_Impl::iterator pElementIter = m_aChildrenVector.begin();
while ( pElementIter != m_aChildrenList.end() ) while ( pElementIter != m_aChildrenVector.end() )
{ {
if ( (*pElementIter)->m_bIsInserted ) if ( (*pElementIter)->m_bIsInserted )
{ {
SotElement_Impl* pToDelete = *pElementIter; delete *pElementIter;
pElementIter = m_aChildrenVector.erase(pElementIter);
++pElementIter; // to let the iterator be valid it should be increased before removing
m_aChildrenList.remove( pToDelete );
delete pToDelete;
} }
else else
{ {
@@ -1239,18 +1231,18 @@ void OStorage_Impl::Revert()
} }
// return replaced removed elements // return replaced removed elements
for ( SotElementList_Impl::iterator pDeletedIter = m_aDeletedList.begin(); for ( SotElementVector_Impl::iterator pDeletedIter = m_aDeletedVector.begin();
pDeletedIter != m_aDeletedList.end(); pDeletedIter != m_aDeletedVector.end();
++pDeletedIter ) ++pDeletedIter )
{ {
m_aChildrenList.push_back( *pDeletedIter ); m_aChildrenVector.push_back( *pDeletedIter );
ClearElement( *pDeletedIter ); ClearElement( *pDeletedIter );
(*pDeletedIter)->m_aName = (*pDeletedIter)->m_aOriginalName; (*pDeletedIter)->m_aName = (*pDeletedIter)->m_aOriginalName;
(*pDeletedIter)->m_bIsRemoved = false; (*pDeletedIter)->m_bIsRemoved = false;
} }
m_aDeletedList.clear(); m_aDeletedVector.clear();
m_bControlMediaType = false; m_bControlMediaType = false;
m_bControlVersion = false; m_bControlVersion = false;
@@ -1297,8 +1289,8 @@ SotElement_Impl* OStorage_Impl::FindElement( const OUString& rName )
ReadContents(); ReadContents();
for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); for ( SotElementVector_Impl::iterator pElementIter = m_aChildrenVector.begin();
pElementIter != m_aChildrenList.end(); ++pElementIter ) pElementIter != m_aChildrenVector.end(); ++pElementIter )
{ {
if ( (*pElementIter)->m_aName == rName && !(*pElementIter)->m_bIsRemoved ) if ( (*pElementIter)->m_aName == rName && !(*pElementIter)->m_bIsRemoved )
return *pElementIter; return *pElementIter;
@@ -1332,7 +1324,7 @@ SotElement_Impl* OStorage_Impl::InsertStream( const OUString& aName, bool bEncr
SotElement_Impl* pNewElement = InsertElement( aName, false ); SotElement_Impl* pNewElement = InsertElement( aName, false );
pNewElement->m_xStream.reset(new OWriteStream_Impl(this, xPackageSubStream, m_xPackage, m_xContext, bEncr, m_nStorageType, true)); pNewElement->m_xStream.reset(new OWriteStream_Impl(this, xPackageSubStream, m_xPackage, m_xContext, bEncr, m_nStorageType, true));
m_aChildrenList.push_back( pNewElement ); m_aChildrenVector.push_back( pNewElement );
m_bIsModified = true; m_bIsModified = true;
m_bBroadcastModified = true; m_bBroadcastModified = true;
@@ -1371,7 +1363,7 @@ void OStorage_Impl::InsertRawStream( const OUString& aName, const uno::Reference
// the stream is inserted and must be treated as a committed one // the stream is inserted and must be treated as a committed one
pNewElement->m_xStream->SetToBeCommited(); pNewElement->m_xStream->SetToBeCommited();
m_aChildrenList.push_back( pNewElement ); m_aChildrenVector.push_back( pNewElement );
m_bIsModified = true; m_bIsModified = true;
m_bBroadcastModified = true; m_bBroadcastModified = true;
} }
@@ -1405,7 +1397,7 @@ SotElement_Impl* OStorage_Impl::InsertStorage( const OUString& aName, sal_Int32
pNewElement->m_xStorage.reset(CreateNewStorageImpl(nStorageMode)); pNewElement->m_xStorage.reset(CreateNewStorageImpl(nStorageMode));
m_aChildrenList.push_back( pNewElement ); m_aChildrenVector.push_back( pNewElement );
return pNewElement; return pNewElement;
} }
@@ -1418,8 +1410,8 @@ SotElement_Impl* OStorage_Impl::InsertElement( const OUString& aName, bool bIsSt
SotElement_Impl* pDeletedElm = nullptr; SotElement_Impl* pDeletedElm = nullptr;
for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); for ( SotElementVector_Impl::iterator pElementIter = m_aChildrenVector.begin();
pElementIter != m_aChildrenList.end(); ++pElementIter ) pElementIter != m_aChildrenVector.end(); ++pElementIter )
{ {
if ( (*pElementIter)->m_aName == aName ) if ( (*pElementIter)->m_aName == aName )
{ {
@@ -1440,8 +1432,10 @@ SotElement_Impl* OStorage_Impl::InsertElement( const OUString& aName, bool bIsSt
else else
OpenSubStream( pDeletedElm ); OpenSubStream( pDeletedElm );
m_aChildrenList.remove( pDeletedElm ); // correct usage of list ??? m_aChildrenVector.erase(
m_aDeletedList.push_back( pDeletedElm ); std::remove(m_aChildrenVector.begin(), m_aChildrenVector.end(), pDeletedElm),
m_aChildrenVector.end());
m_aDeletedVector.push_back( pDeletedElm );
} }
// create new element // create new element
@@ -1498,12 +1492,12 @@ uno::Sequence< OUString > OStorage_Impl::GetElementNames()
ReadContents(); ReadContents();
sal_uInt32 nSize = m_aChildrenList.size(); sal_uInt32 nSize = m_aChildrenVector.size();
uno::Sequence< OUString > aElementNames( nSize ); uno::Sequence< OUString > aElementNames( nSize );
sal_uInt32 nInd = 0; sal_uInt32 nInd = 0;
for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); for ( SotElementVector_Impl::iterator pElementIter = m_aChildrenVector.begin();
pElementIter != m_aChildrenList.end(); ++pElementIter ) pElementIter != m_aChildrenVector.end(); ++pElementIter )
{ {
if ( !(*pElementIter)->m_bIsRemoved ) if ( !(*pElementIter)->m_bIsRemoved )
aElementNames[nInd++] = (*pElementIter)->m_aName; aElementNames[nInd++] = (*pElementIter)->m_aName;
@@ -1526,8 +1520,8 @@ void OStorage_Impl::RemoveElement( SotElement_Impl* pElement )
if ( pElement->m_bIsInserted ) if ( pElement->m_bIsInserted )
{ {
m_aChildrenList.remove( pElement ); delete pElement;
delete pElement; // ??? m_aChildrenVector.erase(std::remove(m_aChildrenVector.begin(), m_aChildrenVector.end(), pElement), m_aChildrenVector.end());
} }
else else
{ {
@@ -2406,8 +2400,8 @@ uno::Reference< embed::XStorage > SAL_CALL OStorage::openStorageElement(
if ( nStorageMode & embed::ElementModes::TRUNCATE ) if ( nStorageMode & embed::ElementModes::TRUNCATE )
{ {
for ( SotElementList_Impl::iterator pElementIter = pElement->m_xStorage->m_aChildrenList.begin(); for ( SotElementVector_Impl::iterator pElementIter = pElement->m_xStorage->m_aChildrenVector.begin();
pElementIter != pElement->m_xStorage->m_aChildrenList.end(); ) pElementIter != pElement->m_xStorage->m_aChildrenVector.end(); )
{ {
SotElement_Impl* pElementToDel = (*pElementIter); SotElement_Impl* pElementToDel = (*pElementIter);
++pElementIter; ++pElementIter;
@@ -3631,8 +3625,8 @@ void SAL_CALL OStorage::revert()
throw lang::DisposedException( THROW_WHERE ); throw lang::DisposedException( THROW_WHERE );
} }
for ( SotElementList_Impl::iterator pElementIter = m_pImpl->m_aChildrenList.begin(); for ( SotElementVector_Impl::iterator pElementIter = m_pImpl->m_aChildrenVector.begin();
pElementIter != m_pImpl->m_aChildrenList.end(); ++pElementIter ) pElementIter != m_pImpl->m_aChildrenVector.end(); ++pElementIter )
{ {
if ( ((*pElementIter)->m_xStorage if ( ((*pElementIter)->m_xStorage
&& ( (*pElementIter)->m_xStorage->m_pAntiImpl || !(*pElementIter)->m_xStorage->m_aReadOnlyWrapVector.empty() )) && ( (*pElementIter)->m_xStorage->m_pAntiImpl || !(*pElementIter)->m_xStorage->m_aReadOnlyWrapVector.empty() ))
@@ -3936,7 +3930,7 @@ sal_Bool SAL_CALL OStorage::hasElements()
try try
{ {
return ( m_pImpl->GetChildrenList().size() != 0 ); return ( m_pImpl->GetChildrenVector().size() != 0 );
} }
catch( const uno::RuntimeException& rRuntimeException ) catch( const uno::RuntimeException& rRuntimeException )
{ {

View File

@@ -92,7 +92,7 @@ public:
SotElement_Impl(const OUString& rName, bool bStor, bool bNew); SotElement_Impl(const OUString& rName, bool bStor, bool bNew);
}; };
typedef ::std::list< SotElement_Impl* > SotElementList_Impl; typedef ::std::vector< SotElement_Impl* > SotElementVector_Impl;
// Main storage implementation // Main storage implementation
@@ -138,8 +138,8 @@ struct OStorage_Impl
return m_nModifiedListenerCount > 0 && m_pAntiImpl != nullptr; return m_nModifiedListenerCount > 0 && m_pAntiImpl != nullptr;
} }
SotElementList_Impl m_aChildrenList; SotElementVector_Impl m_aChildrenVector;
SotElementList_Impl m_aDeletedList; SotElementVector_Impl m_aDeletedVector;
css::uno::Reference< css::container::XNameContainer > m_xPackageFolder; css::uno::Reference< css::container::XNameContainer > m_xPackageFolder;
@@ -204,7 +204,7 @@ struct OStorage_Impl
void ReadContents(); void ReadContents();
void ReadRelInfoIfNecessary(); void ReadRelInfoIfNecessary();
SotElementList_Impl& GetChildrenList(); SotElementVector_Impl& GetChildrenVector();
void GetStorageProperties(); void GetStorageProperties();
css::uno::Sequence< css::uno::Sequence< css::beans::StringPair > > GetAllRelationshipsIfAny(); css::uno::Sequence< css::uno::Sequence< css::beans::StringPair > > GetAllRelationshipsIfAny();