sd/inc/OutlinerIterator.hxx | 2 sd/source/ui/view/OutlinerIterator.cxx | 8 +-- sw/source/core/inc/txtfly.hxx | 13 +++--- sw/source/core/text/txtfly.cxx | 67 ++++++++++++--------------------- 4 files changed, 39 insertions(+), 51 deletions(-)
New commits: commit 0ba5628811c111bc6927ec165be8fa8bdf4b2f7d Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Aug 22 11:23:36 2018 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed Aug 22 13:35:56 2018 +0200 loplugin:useuniqueptr in SwContourCache and simplify, std::vector is easier than keeping an array and our own count Change-Id: I8662063e7914a2f7dacd40f7c20dd1f924ea70dd Reviewed-on: https://gerrit.libreoffice.org/59433 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/core/inc/txtfly.hxx b/sw/source/core/inc/txtfly.hxx index b97c078cb4c4..ddf636cd5f77 100644 --- a/sw/source/core/inc/txtfly.hxx +++ b/sw/source/core/inc/txtfly.hxx @@ -54,10 +54,13 @@ void ClrContourCache( const SdrObject *pObj ); class SwContourCache { friend void ClrContourCache(); - const SdrObject *pSdrObj[ POLY_CNT ]; - TextRanger *pTextRanger[ POLY_CNT ]; + struct CacheItem + { + const SdrObject *mpSdrObj; + std::unique_ptr<TextRanger> mxTextRanger; + }; + std::vector<CacheItem> mvItems; long nPntCnt; - sal_uInt16 nObjCnt; const SwRect ContourRect( const SwFormat* pFormat, const SdrObject* pObj, const SwTextFrame* pFrame, const SwRect &rLine, const long nXPos, const bool bRight ); @@ -65,8 +68,8 @@ class SwContourCache public: SwContourCache(); ~SwContourCache(); - const SdrObject* GetObject( sal_uInt16 nPos ) const{ return pSdrObj[ nPos ]; } - sal_uInt16 GetCount() const { return nObjCnt; } + const SdrObject* GetObject( sal_uInt16 nPos ) const{ return mvItems[ nPos ].mpSdrObj; } + sal_uInt16 GetCount() const { return mvItems.size(); } void ClrObject( sal_uInt16 nPos ); /** diff --git a/sw/source/core/text/txtfly.cxx b/sw/source/core/text/txtfly.cxx index 45950b93ec6b..fca78fe32c25 100644 --- a/sw/source/core/text/txtfly.cxx +++ b/sw/source/core/text/txtfly.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <o3tl/make_unique.hxx> #include <vcl/outdev.hxx> #include <vcl/virdev.hxx> @@ -121,28 +122,18 @@ namespace } SwContourCache::SwContourCache() : - nPntCnt( 0 ), nObjCnt( 0 ) + nPntCnt( 0 ) { - memset( pSdrObj, 0, sizeof(pSdrObj) ); - memset( pTextRanger, 0, sizeof(pTextRanger) ); } SwContourCache::~SwContourCache() { - for( sal_uInt16 i = 0; i < nObjCnt; delete pTextRanger[ i++ ] ) - ; } void SwContourCache::ClrObject( sal_uInt16 nPos ) { - assert(pTextRanger[nPos] && "ClrObject: Already cleared. Good Bye!"); - nPntCnt -= pTextRanger[ nPos ]->GetPointCount(); - delete pTextRanger[ nPos ]; - --nObjCnt; - memmove( const_cast<SdrObject**>(pSdrObj) + nPos, pSdrObj + nPos + 1, - ( nObjCnt - nPos ) * sizeof( SdrObject* ) ); - memmove( pTextRanger + nPos, pTextRanger + nPos + 1, - ( nObjCnt - nPos ) * sizeof( TextRanger* ) ); + nPntCnt -= mvItems[ nPos ].mxTextRanger->GetPointCount(); + mvItems.erase(mvItems.begin() + nPos); } void ClrContourCache( const SdrObject *pObj ) @@ -160,10 +151,7 @@ void ClrContourCache() { if( pContourCache ) { - for( sal_uInt16 i = 0; i < pContourCache->GetCount(); - delete pContourCache->pTextRanger[ i++ ] ) - ; - pContourCache->nObjCnt = 0; + pContourCache->mvItems.clear(); pContourCache->nPntCnt = 0; } } @@ -223,14 +211,14 @@ const SwRect SwContourCache::ContourRect( const SwFormat* pFormat, { SwRect aRet; sal_uInt16 nPos = 0; // Search in the Cache - while( nPos < GetCount() && pObj != pSdrObj[ nPos ] ) + while( nPos < GetCount() && pObj != mvItems[ nPos ].mpSdrObj ) ++nPos; if( GetCount() == nPos ) // Not found { - if( nObjCnt == POLY_CNT ) + if( GetCount() == POLY_CNT ) { - nPntCnt -= pTextRanger[ --nObjCnt ]->GetPointCount(); - delete pTextRanger[ nObjCnt ]; + nPntCnt -= mvItems.back().mxTextRanger->GetPointCount(); + mvItems.pop_back(); } ::basegfx::B2DPolyPolygon aPolyPolygon; ::basegfx::B2DPolyPolygon* pPolyPolygon = nullptr; @@ -258,33 +246,30 @@ const SwRect SwContourCache::ContourRect( const SwFormat* pFormat, } const SvxLRSpaceItem &rLRSpace = pFormat->GetLRSpace(); const SvxULSpaceItem &rULSpace = pFormat->GetULSpace(); - memmove( pTextRanger + 1, pTextRanger, nObjCnt * sizeof( TextRanger* ) ); - memmove( const_cast<SdrObject**>(pSdrObj) + 1, pSdrObj, nObjCnt++ * sizeof( SdrObject* ) ); - pSdrObj[ 0 ] = pObj; // due to #37347 the Object must be entered only - // after GetContour() - pTextRanger[ 0 ] = new TextRanger( aPolyPolygon, pPolyPolygon, 20, - static_cast<sal_uInt16>(rLRSpace.GetLeft()), static_cast<sal_uInt16>(rLRSpace.GetRight()), - pFormat->GetSurround().IsOutside(), false, pFrame->IsVertical() ); - pTextRanger[ 0 ]->SetUpper( rULSpace.GetUpper() ); - pTextRanger[ 0 ]->SetLower( rULSpace.GetLower() ); + CacheItem item { + pObj, // due to #37347 the Object must be entered only after GetContour() + o3tl::make_unique<TextRanger>( aPolyPolygon, pPolyPolygon, 20, + static_cast<sal_uInt16>(rLRSpace.GetLeft()), static_cast<sal_uInt16>(rLRSpace.GetRight()), + pFormat->GetSurround().IsOutside(), false, pFrame->IsVertical() ) + }; + mvItems.insert(mvItems.begin(), std::move(item)); + mvItems[0].mxTextRanger->SetUpper( rULSpace.GetUpper() ); + mvItems[0].mxTextRanger->SetLower( rULSpace.GetLower() ); delete pPolyPolygon; - nPntCnt += pTextRanger[ 0 ]->GetPointCount(); - while( nPntCnt > POLY_MAX && nObjCnt > POLY_MIN ) + nPntCnt += mvItems[0].mxTextRanger->GetPointCount(); + while( nPntCnt > POLY_MAX && mvItems.size() > POLY_MIN ) { - nPntCnt -= pTextRanger[ --nObjCnt ]->GetPointCount(); - delete pTextRanger[ nObjCnt ]; + nPntCnt -= mvItems.back().mxTextRanger->GetPointCount(); + mvItems.pop_back(); } } else if( nPos ) { - const SdrObject* pTmpObj = pSdrObj[ nPos ]; - TextRanger* pTmpRanger = pTextRanger[ nPos ]; - memmove( const_cast<SdrObject**>(pSdrObj) + 1, pSdrObj, nPos * sizeof( SdrObject* ) ); - memmove( pTextRanger + 1, pTextRanger, nPos * sizeof( TextRanger* ) ); - pSdrObj[ 0 ] = pTmpObj; - pTextRanger[ 0 ] = pTmpRanger; + CacheItem item = std::move(mvItems[nPos]); + mvItems.erase(mvItems.begin() + nPos); + mvItems.insert(mvItems.begin(), std::move(item)); } SwRectFnSet aRectFnSet(pFrame); long nTmpTop = aRectFnSet.GetTop(rLine); @@ -293,7 +278,7 @@ const SwRect SwContourCache::ContourRect( const SwFormat* pFormat, Range aRange( std::min( nTmpTop, nTmpBottom ), std::max( nTmpTop, nTmpBottom ) ); - LongDqPtr pTmp = pTextRanger[ 0 ]->GetTextRanges( aRange ); + LongDqPtr pTmp = mvItems[0].mxTextRanger->GetTextRanges( aRange ); const size_t nCount = pTmp->size(); if( 0 != nCount ) commit 04c790949bb8311517c1fc1bfb6c15f207041f5d Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Aug 22 11:50:12 2018 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed Aug 22 13:35:47 2018 +0200 loplugin:useuniqueptr in sd::Outline::Iterator Change-Id: I5f8281efb09c1da7c12e80d2522b89bbd400c3f7 Reviewed-on: https://gerrit.libreoffice.org/59435 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sd/inc/OutlinerIterator.hxx b/sd/inc/OutlinerIterator.hxx index 38899e763709..523eaf640c3a 100644 --- a/sd/inc/OutlinerIterator.hxx +++ b/sd/inc/OutlinerIterator.hxx @@ -88,7 +88,7 @@ public: @param pObject A copy of this object will become the implementation object. */ - explicit Iterator (IteratorImplBase* pObject); + explicit Iterator (std::unique_ptr<IteratorImplBase> pObject); ~Iterator(); diff --git a/sd/source/ui/view/OutlinerIterator.cxx b/sd/source/ui/view/OutlinerIterator.cxx index ee805e17c8a9..5458eca52d28 100644 --- a/sd/source/ui/view/OutlinerIterator.cxx +++ b/sd/source/ui/view/OutlinerIterator.cxx @@ -69,8 +69,8 @@ Iterator::Iterator (Iterator&& rIterator) { } -Iterator::Iterator (IteratorImplBase* pObject) - : mxIterator(pObject) +Iterator::Iterator (std::unique_ptr<IteratorImplBase> pObject) + : mxIterator(std::move(pObject)) { } @@ -207,7 +207,7 @@ Iterator OutlinerContainer::CreateSelectionIterator ( break; } - return Iterator (new SelectionIteratorImpl ( + return Iterator (o3tl::make_unique<SelectionIteratorImpl> ( rObjectList, nObjectIndex, pDocument, rpViewShell, bDirectionIsForward)); } @@ -271,7 +271,7 @@ Iterator OutlinerContainer::CreateDocumentIterator ( ePageKind, eEditMode, bDirectionIsForward, aLocation); return Iterator ( - new DocumentIteratorImpl (nPageIndex, ePageKind, eEditMode, + o3tl::make_unique<DocumentIteratorImpl> (nPageIndex, ePageKind, eEditMode, pDocument, rpViewShell, bDirectionIsForward)); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits