Kaydet (Commit) bb2ff075 authored tarafından Noel Grandin's avatar Noel Grandin

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: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 49ea3206
...@@ -97,6 +97,17 @@ public: ...@@ -97,6 +97,17 @@ public:
m_vector.begin() + (last - m_vector.begin())); 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() void clear()
{ {
m_vector.clear(); m_vector.clear();
......
...@@ -122,8 +122,8 @@ public: ...@@ -122,8 +122,8 @@ public:
}; };
class SwHTMLPosFlyFrames class SwHTMLPosFlyFrames
: public o3tl::sorted_vector<SwHTMLPosFlyFrame*, : public o3tl::sorted_vector<std::unique_ptr<SwHTMLPosFlyFrame>,
o3tl::less_ptr_to<SwHTMLPosFlyFrame>, o3tl::less_uniqueptr_to<SwHTMLPosFlyFrame>,
o3tl::find_partialorder_ptrequals> o3tl::find_partialorder_ptrequals>
{}; {};
......
...@@ -249,7 +249,7 @@ sal_uInt16 SwHTMLWriter::GuessFrameType( const SwFrameFormat& rFrameFormat, ...@@ -249,7 +249,7 @@ sal_uInt16 SwHTMLWriter::GuessFrameType( const SwFrameFormat& rFrameFormat,
bEmpty = true; bEmpty = true;
if( m_pHTMLPosFlyFrames ) if( m_pHTMLPosFlyFrames )
{ {
for( auto pHTMLPosFlyFrame : *m_pHTMLPosFlyFrames ) for( auto & pHTMLPosFlyFrame : *m_pHTMLPosFlyFrames )
{ {
sal_uLong nIdx = pHTMLPosFlyFrame->GetNdIndex().GetIndex(); sal_uLong nIdx = pHTMLPosFlyFrame->GetNdIndex().GetIndex();
bEmpty = (nIdx != nStt) && (nIdx != nStt-1); bEmpty = (nIdx != nStt) && (nIdx != nStt-1);
...@@ -348,8 +348,7 @@ void SwHTMLWriter::CollectFlyFrames() ...@@ -348,8 +348,7 @@ void SwHTMLWriter::CollectFlyFrames()
if( !m_pHTMLPosFlyFrames ) if( !m_pHTMLPosFlyFrames )
m_pHTMLPosFlyFrames.reset(new SwHTMLPosFlyFrames); m_pHTMLPosFlyFrames.reset(new SwHTMLPosFlyFrames);
SwHTMLPosFlyFrame *pNew = new SwHTMLPosFlyFrame(**aIter, pSdrObj, nMode); m_pHTMLPosFlyFrames->insert( o3tl::make_unique<SwHTMLPosFlyFrame>(**aIter, pSdrObj, nMode) );
m_pHTMLPosFlyFrames->insert( pNew );
} }
} }
...@@ -374,7 +373,7 @@ bool SwHTMLWriter::OutFlyFrame( sal_uLong nNdIdx, sal_Int32 nContentIdx, HtmlPos ...@@ -374,7 +373,7 @@ bool SwHTMLWriter::OutFlyFrame( sal_uLong nNdIdx, sal_Int32 nContentIdx, HtmlPos
for( ; !bRestart && i < m_pHTMLPosFlyFrames->size() && for( ; !bRestart && i < m_pHTMLPosFlyFrames->size() &&
(*m_pHTMLPosFlyFrames)[i]->GetNdIndex().GetIndex() == nNdIdx; i++ ) (*m_pHTMLPosFlyFrames)[i]->GetNdIndex().GetIndex() == nNdIdx; i++ )
{ {
SwHTMLPosFlyFrame *pPosFly = (*m_pHTMLPosFlyFrames)[i]; SwHTMLPosFlyFrame *pPosFly = (*m_pHTMLPosFlyFrames)[i].get();
if( ( HtmlPosition::Any == nPos || if( ( HtmlPosition::Any == nPos ||
pPosFly->GetOutPos() == nPos ) && pPosFly->GetOutPos() == nPos ) &&
pPosFly->GetContentIndex() == nContentIdx ) pPosFly->GetContentIndex() == nContentIdx )
...@@ -382,7 +381,7 @@ bool SwHTMLWriter::OutFlyFrame( sal_uLong nNdIdx, sal_Int32 nContentIdx, HtmlPos ...@@ -382,7 +381,7 @@ bool SwHTMLWriter::OutFlyFrame( sal_uLong nNdIdx, sal_Int32 nContentIdx, HtmlPos
// It is important to remove it first, because additional // It is important to remove it first, because additional
// elements or the whole array could be deleted on // elements or the whole array could be deleted on
// deeper recursion levels. // deeper recursion levels.
m_pHTMLPosFlyFrames->erase(i); std::unique_ptr<SwHTMLPosFlyFrame> flyHolder = m_pHTMLPosFlyFrames->erase_extract(i);
i--; i--;
if( m_pHTMLPosFlyFrames->empty() ) if( m_pHTMLPosFlyFrames->empty() )
{ {
...@@ -408,7 +407,6 @@ bool SwHTMLWriter::OutFlyFrame( sal_uLong nNdIdx, sal_Int32 nContentIdx, HtmlPos ...@@ -408,7 +407,6 @@ bool SwHTMLWriter::OutFlyFrame( sal_uLong nNdIdx, sal_Int32 nContentIdx, HtmlPos
break; break;
default: break; default: break;
} }
delete pPosFly;
} }
else else
{ {
......
...@@ -1332,7 +1332,7 @@ void SwHTMLWriter::GetControls() ...@@ -1332,7 +1332,7 @@ void SwHTMLWriter::GetControls()
// collect the paragraph-bound controls // collect the paragraph-bound controls
for( size_t i=0; i<m_pHTMLPosFlyFrames->size(); i++ ) 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() ) if( HtmlOut::Control != pPosFlyFrame->GetOutFn() )
continue; continue;
......
...@@ -480,11 +480,7 @@ ErrCode SwHTMLWriter::WriteStream() ...@@ -480,11 +480,7 @@ ErrCode SwHTMLWriter::WriteStream()
// delete the table with floating frames // delete the table with floating frames
OSL_ENSURE( !m_pHTMLPosFlyFrames, "Were not all frames output?" ); OSL_ENSURE( !m_pHTMLPosFlyFrames, "Were not all frames output?" );
if( m_pHTMLPosFlyFrames )
{
m_pHTMLPosFlyFrames->DeleteAndDestroyAll();
m_pHTMLPosFlyFrames.reset(); m_pHTMLPosFlyFrames.reset();
}
m_aHTMLControls.clear(); m_aHTMLControls.clear();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment