diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-04-23 09:51:55 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-04-24 08:21:47 +0200 |
commit | 148b84160667ed3ec74c8767f6e62567479488f9 (patch) | |
tree | e4b3348ad2bf894d6719c938c4503f53627f5204 /vcl | |
parent | 447d4e1366cf176c6ff2c6eebf3cf8a65745a7dc (diff) |
loplugin:useuniqueptr in TETextPortionList
Change-Id: Ia4ba670cc524a0103dbab0880931279bafd0925e
Reviewed-on: https://gerrit.libreoffice.org/53347
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/edit/textdat2.hxx | 18 | ||||
-rw-r--r-- | vcl/source/edit/textdata.cxx | 28 | ||||
-rw-r--r-- | vcl/source/edit/texteng.cxx | 18 |
3 files changed, 30 insertions, 34 deletions
diff --git a/vcl/source/edit/textdat2.hxx b/vcl/source/edit/textdat2.hxx index 27b110b6e322..29589aadcffd 100644 --- a/vcl/source/edit/textdat2.hxx +++ b/vcl/source/edit/textdat2.hxx @@ -72,7 +72,7 @@ public: class TETextPortionList { private: - std::vector<TETextPortion*> maPortions; + std::vector<std::unique_ptr<TETextPortion>> maPortions; public: static constexpr auto npos = std::numeric_limits<std::size_t>::max(); @@ -81,16 +81,16 @@ public: ~TETextPortionList(); TETextPortion* operator[]( std::size_t nPos ); - std::vector<TETextPortion*>::iterator begin(); - std::vector<TETextPortion*>::const_iterator begin() const; - std::vector<TETextPortion*>::iterator end(); - std::vector<TETextPortion*>::const_iterator end() const; + std::vector<std::unique_ptr<TETextPortion>>::iterator begin(); + std::vector<std::unique_ptr<TETextPortion>>::const_iterator begin() const; + std::vector<std::unique_ptr<TETextPortion>>::iterator end(); + std::vector<std::unique_ptr<TETextPortion>>::const_iterator end() const; bool empty() const; std::size_t size() const; - std::vector<TETextPortion*>::iterator erase( const std::vector<TETextPortion*>::iterator& aIter ); - std::vector<TETextPortion*>::iterator insert( const std::vector<TETextPortion*>::iterator& aIter, - TETextPortion* pTP ); - void push_back( TETextPortion* pTP ); + std::vector<std::unique_ptr<TETextPortion>>::iterator erase( const std::vector<std::unique_ptr<TETextPortion>>::iterator& aIter ); + std::vector<std::unique_ptr<TETextPortion>>::iterator insert( const std::vector<std::unique_ptr<TETextPortion>>::iterator& aIter, + std::unique_ptr<TETextPortion> pTP ); + void push_back( std::unique_ptr<TETextPortion> pTP ); void Reset(); std::size_t FindPortion( sal_Int32 nCharPos, sal_Int32& rPortionStart, bool bPreferStartingPortion = false ); diff --git a/vcl/source/edit/textdata.cxx b/vcl/source/edit/textdata.cxx index bc8302174cab..6f048175b5f2 100644 --- a/vcl/source/edit/textdata.cxx +++ b/vcl/source/edit/textdata.cxx @@ -60,25 +60,25 @@ TETextPortionList::~TETextPortionList() TETextPortion* TETextPortionList::operator[]( std::size_t nPos ) { - return maPortions[ nPos ]; + return maPortions[ nPos ].get(); } -std::vector<TETextPortion*>::iterator TETextPortionList::begin() +std::vector<std::unique_ptr<TETextPortion>>::iterator TETextPortionList::begin() { return maPortions.begin(); } -std::vector<TETextPortion*>::const_iterator TETextPortionList::begin() const +std::vector<std::unique_ptr<TETextPortion>>::const_iterator TETextPortionList::begin() const { return maPortions.begin(); } -std::vector<TETextPortion*>::iterator TETextPortionList::end() +std::vector<std::unique_ptr<TETextPortion>>::iterator TETextPortionList::end() { return maPortions.end(); } -std::vector<TETextPortion*>::const_iterator TETextPortionList::end() const +std::vector<std::unique_ptr<TETextPortion>>::const_iterator TETextPortionList::end() const { return maPortions.end(); } @@ -93,34 +93,30 @@ std::size_t TETextPortionList::size() const return maPortions.size(); } -std::vector<TETextPortion*>::iterator TETextPortionList::erase( const std::vector<TETextPortion*>::iterator& aIter ) +std::vector<std::unique_ptr<TETextPortion>>::iterator TETextPortionList::erase( const std::vector<std::unique_ptr<TETextPortion>>::iterator& aIter ) { return maPortions.erase( aIter ); } -std::vector<TETextPortion*>::iterator TETextPortionList::insert( const std::vector<TETextPortion*>::iterator& aIter, - TETextPortion* pTP ) +std::vector<std::unique_ptr<TETextPortion>>::iterator TETextPortionList::insert( const std::vector<std::unique_ptr<TETextPortion>>::iterator& aIter, + std::unique_ptr<TETextPortion> pTP ) { - return maPortions.insert( aIter, pTP ); + return maPortions.insert( aIter, std::move(pTP) ); } -void TETextPortionList::push_back( TETextPortion* pTP ) +void TETextPortionList::push_back( std::unique_ptr<TETextPortion> pTP ) { - maPortions.push_back( pTP ); + maPortions.push_back( std::move(pTP) ); } void TETextPortionList::Reset() { - for ( auto pTP : maPortions ) - delete pTP; maPortions.clear(); } void TETextPortionList::DeleteFromPortion( std::size_t nDelFrom ) { SAL_WARN_IF( ( nDelFrom >= maPortions.size() ) && ( (nDelFrom != 0) || (maPortions.size() != 0) ), "vcl", "DeleteFromPortion: Out of range" ); - for ( auto it = maPortions.begin() + nDelFrom; it != maPortions.end(); ++it ) - delete *it; maPortions.erase( maPortions.begin() + nDelFrom, maPortions.end() ); } @@ -130,7 +126,7 @@ std::size_t TETextPortionList::FindPortion( sal_Int32 nCharPos, sal_Int32& nPort sal_Int32 nTmpPos = 0; for ( std::size_t nPortion = 0; nPortion < maPortions.size(); nPortion++ ) { - TETextPortion* pPortion = maPortions[ nPortion ]; + TETextPortion* pPortion = maPortions[ nPortion ].get(); nTmpPos += pPortion->GetLen(); if ( nTmpPos >= nCharPos ) { diff --git a/vcl/source/edit/texteng.cxx b/vcl/source/edit/texteng.cxx index e382a514ee4c..0884040c94b1 100644 --- a/vcl/source/edit/texteng.cxx +++ b/vcl/source/edit/texteng.cxx @@ -1612,9 +1612,9 @@ void TextEngine::CreateAndInsertEmptyLine( sal_uInt32 nPara ) bool bLineBreak = !pNode->GetText().isEmpty(); - TETextPortion* pDummyPortion = new TETextPortion( 0 ); + std::unique_ptr<TETextPortion> pDummyPortion(new TETextPortion( 0 )); pDummyPortion->GetWidth() = 0; - pTEParaPortion->GetTextPortions().push_back( pDummyPortion ); + pTEParaPortion->GetTextPortions().push_back( std::move(pDummyPortion) ); if ( bLineBreak ) { @@ -1704,8 +1704,8 @@ std::size_t TextEngine::SplitTextPortion( sal_uInt32 nPara, sal_Int32 nPos ) const sal_Int32 nOverlapp = nTmpPos - nPos; pTextPortion->GetLen() -= nOverlapp; - TETextPortion* pNewPortion = new TETextPortion( nOverlapp ); - pTEParaPortion->GetTextPortions().insert( pTEParaPortion->GetTextPortions().begin() + nSplitPortion + 1, pNewPortion ); + std::unique_ptr<TETextPortion> pNewPortion( new TETextPortion( nOverlapp ) ); + pTEParaPortion->GetTextPortions().insert( pTEParaPortion->GetTextPortions().begin() + nSplitPortion + 1, std::move(pNewPortion) ); pTextPortion->GetWidth() = CalcTextWidth( nPara, nPos-pTextPortion->GetLen(), pTextPortion->GetLen() ); return nSplitPortion; @@ -1797,8 +1797,8 @@ void TextEngine::CreateTextPortions( sal_uInt32 nPara, sal_Int32 nStartPos ) std::set<sal_Int32>::iterator nextIt = aPositionsIt; for ( ++nextIt; nextIt != aPositions.end(); ++aPositionsIt, ++nextIt ) { - TETextPortion* pNew = new TETextPortion( *nextIt - *aPositionsIt ); - pTEParaPortion->GetTextPortions().push_back( pNew ); + std::unique_ptr<TETextPortion> pNew( new TETextPortion( *nextIt - *aPositionsIt ) ); + pTEParaPortion->GetTextPortions().push_back( std::move(pNew) ); } } OSL_ENSURE(pTEParaPortion->GetTextPortions().size(), "CreateTextPortions: No Portions?!"); @@ -1835,8 +1835,8 @@ void TextEngine::RecalcTextPortion( sal_uInt32 nPara, sal_Int32 nStartPos, sal_I } else { - TETextPortion* pNewPortion = new TETextPortion( nNewChars ); - pTEParaPortion->GetTextPortions().insert( pTEParaPortion->GetTextPortions().begin() + nNewPortionPos, pNewPortion ); + std::unique_ptr<TETextPortion> pNewPortion(new TETextPortion( nNewChars )); + pTEParaPortion->GetTextPortions().insert( pTEParaPortion->GetTextPortions().begin() + nNewPortionPos, std::move(pNewPortion) ); } } else @@ -2112,7 +2112,7 @@ bool TextEngine::CreateLines( sal_uInt32 nPara ) { // check if deleting across Portion border sal_Int32 nPos = 0; - for ( const auto pTP : pTEParaPortion->GetTextPortions() ) + for ( const auto & pTP : pTEParaPortion->GetTextPortions() ) { // there must be no Start/End in the deleted region nPos += pTP->GetLen(); |