[Libreoffice-commits] core.git: sw/inc sw/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Thu Sep 20 06:15:44 UTC 2018
sw/inc/edglbldc.hxx | 5 +----
sw/source/core/edit/edglbldc.cxx | 27 +++++++++++----------------
sw/source/uibase/utlui/glbltree.cxx | 21 +++++++++------------
3 files changed, 21 insertions(+), 32 deletions(-)
New commits:
commit 97c934d96be62f906c48561673866399f6469446
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Sep 18 14:32:11 2018 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Sep 20 08:15:22 2018 +0200
convert SwGlblDocContents to sorted_vector<unique_ptr<>>
Change-Id: I9766a03739aa63be8f42fc99012577cfa154298d
Reviewed-on: https://gerrit.libreoffice.org/60738
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sw/inc/edglbldc.hxx b/sw/inc/edglbldc.hxx
index 2dabd5165643..ee246d006c73 100644
--- a/sw/inc/edglbldc.hxx
+++ b/sw/inc/edglbldc.hxx
@@ -60,10 +60,7 @@ public:
{ return GetDocPos() < rCmp.GetDocPos(); }
};
-class SwGlblDocContents : public o3tl::sorted_vector<SwGlblDocContent*, o3tl::less_ptr_to<SwGlblDocContent> > {
-public:
- ~SwGlblDocContents() { DeleteAndDestroyAll(); }
-};
+class SwGlblDocContents : public o3tl::sorted_vector<std::unique_ptr<SwGlblDocContent>, o3tl::less_uniqueptr_to<SwGlblDocContent> > {};
#endif
diff --git a/sw/source/core/edit/edglbldc.cxx b/sw/source/core/edit/edglbldc.cxx
index e2f4dd71f7bf..fc7d8b241b89 100644
--- a/sw/source/core/edit/edglbldc.cxx
+++ b/sw/source/core/edit/edglbldc.cxx
@@ -53,7 +53,7 @@ bool SwEditShell::IsGlblDocSaveLinks() const
void SwEditShell::GetGlobalDocContent( SwGlblDocContents& rArr ) const
{
- rArr.DeleteAndDestroyAll();
+ rArr.clear();
if( !getIDocumentSettingAccess().get(DocumentSettingId::GLOBAL_DOCUMENT) )
return;
@@ -67,22 +67,21 @@ void SwEditShell::GetGlobalDocContent( SwGlblDocContents& rArr ) const
const SwSection* pSect = rSectFormats[ --n ]->GetGlobalDocSection();
if( pSect )
{
- SwGlblDocContent* pNew = nullptr;
+ std::unique_ptr<SwGlblDocContent> pNew;
switch( pSect->GetType() )
{
case TOX_HEADER_SECTION:
break; // ignore
case TOX_CONTENT_SECTION:
OSL_ENSURE( dynamic_cast<const SwTOXBaseSection*>( pSect) != nullptr, "no TOXBaseSection!" );
- pNew = new SwGlblDocContent( static_cast<const SwTOXBaseSection*>(pSect) );
+ pNew.reset(new SwGlblDocContent( static_cast<const SwTOXBaseSection*>(pSect) ));
break;
default:
- pNew = new SwGlblDocContent( pSect );
+ pNew.reset(new SwGlblDocContent( pSect ));
break;
}
- if( pNew && !rArr.insert( pNew ).second )
- delete pNew;
+ rArr.insert( std::move(pNew) );
}
}
@@ -98,10 +97,8 @@ void SwEditShell::GetGlobalDocContent( SwGlblDocContents& rArr ) const
if( ( pNd = pMyDoc->GetNodes()[ nSttIdx ])->IsContentNode()
|| pNd->IsSectionNode() || pNd->IsTableNode() )
{
- SwGlblDocContent* pNew = new SwGlblDocContent( nSttIdx );
- if( !rArr.insert( pNew ).second )
- delete pNew;
- else
+ std::unique_ptr<SwGlblDocContent> pNew(new SwGlblDocContent( nSttIdx ));
+ if( rArr.insert( std::move(pNew) ).second )
++n; // to the next position
break;
}
@@ -119,17 +116,15 @@ void SwEditShell::GetGlobalDocContent( SwGlblDocContents& rArr ) const
if( ( pNd = pMyDoc->GetNodes()[ nSttIdx ])->IsContentNode()
|| pNd->IsSectionNode() || pNd->IsTableNode() )
{
- SwGlblDocContent* pNew = new SwGlblDocContent( nSttIdx );
- if( !rArr.insert( pNew ).second )
- delete pNew;
+ rArr.insert( o3tl::make_unique<SwGlblDocContent>( nSttIdx ) );
break;
}
}
else
{
- SwGlblDocContent* pNew = new SwGlblDocContent(
- pMyDoc->GetNodes().GetEndOfExtras().GetIndex() + 2 );
- rArr.insert( pNew );
+ std::unique_ptr<SwGlblDocContent> pNew(new SwGlblDocContent(
+ pMyDoc->GetNodes().GetEndOfExtras().GetIndex() + 2 ));
+ rArr.insert( std::move(pNew) );
}
}
diff --git a/sw/source/uibase/utlui/glbltree.cxx b/sw/source/uibase/utlui/glbltree.cxx
index 13cc616041fe..737fd2f1b1e2 100644
--- a/sw/source/uibase/utlui/glbltree.cxx
+++ b/sw/source/uibase/utlui/glbltree.cxx
@@ -270,7 +270,7 @@ sal_Int8 SwGlobalTree::ExecuteDrop( const ExecuteDropEvent& rEvt )
{
nEntryCount++;
nAbsContPos++;
- pCnt = (*pTempContents)[ nAbsContPos ];
+ pCnt = (*pTempContents)[ nAbsContPos ].get();
}
}
}
@@ -659,7 +659,7 @@ void SwGlobalTree::Display(bool bOnlyUpdateUserData)
SvTreeListEntry* pEntry = First();
for (size_t i = 0; i < nCount && pEntry; i++)
{
- SwGlblDocContent* pCont = (*m_pSwGlblDocContents)[i];
+ SwGlblDocContent* pCont = (*m_pSwGlblDocContents)[i].get();
pEntry->SetUserData(pCont);
pEntry = Next(pEntry);
assert(pEntry || i == nCount - 1);
@@ -683,7 +683,7 @@ void SwGlobalTree::Display(bool bOnlyUpdateUserData)
SvTreeListEntry* pSelEntry = nullptr;
for( size_t i = 0; i < nCount; i++)
{
- SwGlblDocContent* pCont = (*m_pSwGlblDocContents)[i];
+ SwGlblDocContent* pCont = (*m_pSwGlblDocContents)[i].get();
OUString sEntry;
Image aImage;
switch( pCont->GetType() )
@@ -1130,8 +1130,8 @@ bool SwGlobalTree::Update(bool bHard)
{
for(size_t i = 0; i < pTempContents->size() && !bCopy; i++)
{
- SwGlblDocContent* pLeft = (*pTempContents)[i];
- SwGlblDocContent* pRight = (*m_pSwGlblDocContents)[i];
+ SwGlblDocContent* pLeft = (*pTempContents)[i].get();
+ SwGlblDocContent* pRight = (*m_pSwGlblDocContents)[i].get();
GlobalDocContentType eType = pLeft->GetType();
SvTreeListEntry* pEntry = GetEntry(i);
OUString sTemp = GetEntryText(pEntry);
@@ -1153,10 +1153,7 @@ bool SwGlobalTree::Update(bool bHard)
}
if(bCopy || bHard)
{
- m_pSwGlblDocContents->DeleteAndDestroyAll();
- m_pSwGlblDocContents->insert( *pTempContents );
- pTempContents->clear();
-
+ *m_pSwGlblDocContents = std::move( *pTempContents );
}
}
@@ -1165,7 +1162,7 @@ bool SwGlobalTree::Update(bool bHard)
{
Clear();
if(m_pSwGlblDocContents)
- m_pSwGlblDocContents->DeleteAndDestroyAll();
+ m_pSwGlblDocContents->clear();
}
// FIXME: Implement a test for changes!
return bRet;
@@ -1308,9 +1305,9 @@ void SwGlobalTree::InsertRegion( const SwGlblDocContent* _pContent, const Sequen
SwGlblDocContent* pAnchorContent = nullptr;
OSL_ENSURE(aTempContents.size() > (nAnchorContent + nFile), "invalid anchor content -> last insertion failed");
if ( aTempContents.size() > (nAnchorContent + nFile) )
- pAnchorContent = aTempContents[nAnchorContent + nFile];
+ pAnchorContent = aTempContents[nAnchorContent + nFile].get();
else
- pAnchorContent = aTempContents.back();
+ pAnchorContent = aTempContents.back().get();
OUString sFileName(pFileNames[nFile]);
INetURLObject aFileUrl;
aFileUrl.SetSmartURL( sFileName );
More information about the Libreoffice-commits
mailing list