summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-10-03 14:29:32 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-10-06 08:16:24 +0200
commitbb2ff075642664084e735948fcc65e21ad861937 (patch)
treeec9db68195bb4af99609e1485d9bd16b453d253b
parent49ea32064a28675a735fd270d07fd6ea8e7e03b6 (diff)
loplugin:useuniqueptr in SwHTMLPosFlyFrames
and add a new method erase_extract to o3tl::sorted_vector, otherwise there is no decent way to extract an element from such a vector without freeing it. Change-Id: I769782c04a54a2d7433e8349c99134f997a54689 Reviewed-on: https://gerrit.libreoffice.org/61345 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--include/o3tl/sorted_vector.hxx11
-rw-r--r--sw/source/filter/html/htmlfly.hxx4
-rw-r--r--sw/source/filter/html/htmlflywriter.cxx10
-rw-r--r--sw/source/filter/html/htmlforw.cxx2
-rw-r--r--sw/source/filter/html/wrthtml.cxx6
5 files changed, 19 insertions, 14 deletions
diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx
index 6e245353fe70..8324e333198a 100644
--- a/include/o3tl/sorted_vector.hxx
+++ b/include/o3tl/sorted_vector.hxx
@@ -97,6 +97,17 @@ public:
m_vector.begin() + (last - m_vector.begin()));
}
+ /**
+ * make erase return the removed element, otherwise there is no useful way of extracting a std::unique_ptr
+ * from this.
+ */
+ Value erase_extract( size_t index )
+ {
+ Value val = std::move(m_vector[index]);
+ m_vector.erase(m_vector.begin() + index);
+ return val;
+ }
+
void clear()
{
m_vector.clear();
diff --git a/sw/source/filter/html/htmlfly.hxx b/sw/source/filter/html/htmlfly.hxx
index 5873baf28dad..f12ea3b5582b 100644
--- a/sw/source/filter/html/htmlfly.hxx
+++ b/sw/source/filter/html/htmlfly.hxx
@@ -122,8 +122,8 @@ public:
};
class SwHTMLPosFlyFrames
- : public o3tl::sorted_vector<SwHTMLPosFlyFrame*,
- o3tl::less_ptr_to<SwHTMLPosFlyFrame>,
+ : public o3tl::sorted_vector<std::unique_ptr<SwHTMLPosFlyFrame>,
+ o3tl::less_uniqueptr_to<SwHTMLPosFlyFrame>,
o3tl::find_partialorder_ptrequals>
{};
diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx
index 9f4987815024..f4f0da70c2f1 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -249,7 +249,7 @@ sal_uInt16 SwHTMLWriter::GuessFrameType( const SwFrameFormat& rFrameFormat,
bEmpty = true;
if( m_pHTMLPosFlyFrames )
{
- for( auto pHTMLPosFlyFrame : *m_pHTMLPosFlyFrames )
+ for( auto & pHTMLPosFlyFrame : *m_pHTMLPosFlyFrames )
{
sal_uLong nIdx = pHTMLPosFlyFrame->GetNdIndex().GetIndex();
bEmpty = (nIdx != nStt) && (nIdx != nStt-1);
@@ -348,8 +348,7 @@ void SwHTMLWriter::CollectFlyFrames()
if( !m_pHTMLPosFlyFrames )
m_pHTMLPosFlyFrames.reset(new SwHTMLPosFlyFrames);
- SwHTMLPosFlyFrame *pNew = new SwHTMLPosFlyFrame(**aIter, pSdrObj, nMode);
- m_pHTMLPosFlyFrames->insert( pNew );
+ m_pHTMLPosFlyFrames->insert( o3tl::make_unique<SwHTMLPosFlyFrame>(**aIter, pSdrObj, nMode) );
}
}
@@ -374,7 +373,7 @@ bool SwHTMLWriter::OutFlyFrame( sal_uLong nNdIdx, sal_Int32 nContentIdx, HtmlPos
for( ; !bRestart && i < m_pHTMLPosFlyFrames->size() &&
(*m_pHTMLPosFlyFrames)[i]->GetNdIndex().GetIndex() == nNdIdx; i++ )
{
- SwHTMLPosFlyFrame *pPosFly = (*m_pHTMLPosFlyFrames)[i];
+ SwHTMLPosFlyFrame *pPosFly = (*m_pHTMLPosFlyFrames)[i].get();
if( ( HtmlPosition::Any == nPos ||
pPosFly->GetOutPos() == nPos ) &&
pPosFly->GetContentIndex() == nContentIdx )
@@ -382,7 +381,7 @@ bool SwHTMLWriter::OutFlyFrame( sal_uLong nNdIdx, sal_Int32 nContentIdx, HtmlPos
// It is important to remove it first, because additional
// elements or the whole array could be deleted on
// deeper recursion levels.
- m_pHTMLPosFlyFrames->erase(i);
+ std::unique_ptr<SwHTMLPosFlyFrame> flyHolder = m_pHTMLPosFlyFrames->erase_extract(i);
i--;
if( m_pHTMLPosFlyFrames->empty() )
{
@@ -408,7 +407,6 @@ bool SwHTMLWriter::OutFlyFrame( sal_uLong nNdIdx, sal_Int32 nContentIdx, HtmlPos
break;
default: break;
}
- delete pPosFly;
}
else
{
diff --git a/sw/source/filter/html/htmlforw.cxx b/sw/source/filter/html/htmlforw.cxx
index 85db134bf892..b3f2d6088c00 100644
--- a/sw/source/filter/html/htmlforw.cxx
+++ b/sw/source/filter/html/htmlforw.cxx
@@ -1332,7 +1332,7 @@ void SwHTMLWriter::GetControls()
// collect the paragraph-bound controls
for( size_t i=0; i<m_pHTMLPosFlyFrames->size(); i++ )
{
- const SwHTMLPosFlyFrame* pPosFlyFrame = (*m_pHTMLPosFlyFrames)[ i ];
+ const SwHTMLPosFlyFrame* pPosFlyFrame = (*m_pHTMLPosFlyFrames)[ i ].get();
if( HtmlOut::Control != pPosFlyFrame->GetOutFn() )
continue;
diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx
index 1095aa60d681..531e14b07852 100644
--- a/sw/source/filter/html/wrthtml.cxx
+++ b/sw/source/filter/html/wrthtml.cxx
@@ -480,11 +480,7 @@ ErrCode SwHTMLWriter::WriteStream()
// delete the table with floating frames
OSL_ENSURE( !m_pHTMLPosFlyFrames, "Were not all frames output?" );
- if( m_pHTMLPosFlyFrames )
- {
- m_pHTMLPosFlyFrames->DeleteAndDestroyAll();
- m_pHTMLPosFlyFrames.reset();
- }
+ m_pHTMLPosFlyFrames.reset();
m_aHTMLControls.clear();