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:
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();
......
......@@ -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>
{};
......
......@@ -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
{
......
......@@ -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;
......
......@@ -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();
......
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