no need to use unique_ptr for PolyPolygon

it is already a COW type

Change-Id: If28f67bff3f8df7763bf4b574b1125d568f0ee27
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120821
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2021-08-21 18:21:48 +02:00 committed by Noel Grandin
parent 008f28c9e0
commit 4c5e264df4
7 changed files with 26 additions and 26 deletions

View file

@ -322,7 +322,7 @@ void ImpEditView::SelectionChanged()
}
// This function is also called when a text's font || size is changed. Because its highlight rectangle must be updated.
void ImpEditView::lokSelectionCallback(const std::unique_ptr<tools::PolyPolygon> &pPolyPoly, bool bStartHandleVisible, bool bEndHandleVisible) {
void ImpEditView::lokSelectionCallback(const std::optional<tools::PolyPolygon> &pPolyPoly, bool bStartHandleVisible, bool bEndHandleVisible) {
VclPtr<vcl::Window> pParent = pOutWin->GetParentWithLOKNotifier();
vcl::Region aRegion( *pPolyPoly );
@ -487,7 +487,7 @@ void ImpEditView::DrawSelectionXOR( EditSelection aTmpSel, vcl::Region* pRegion,
bool bClipRegion = rTarget.IsClipRegion();
vcl::Region aOldRegion = rTarget.GetClipRegion();
std::unique_ptr<tools::PolyPolygon> pPolyPoly;
std::optional<tools::PolyPolygon> pPolyPoly;
if ( !pRegion && !comphelper::LibreOfficeKit::isActive())
{
@ -511,7 +511,7 @@ void ImpEditView::DrawSelectionXOR( EditSelection aTmpSel, vcl::Region* pRegion,
}
if (comphelper::LibreOfficeKit::isActive() || pRegion)
pPolyPoly.reset(new tools::PolyPolygon);
pPolyPoly = tools::PolyPolygon();
DBG_ASSERT( !pEditEngine->IsIdleFormatterActive(), "DrawSelectionXOR: Not formatted!" );
aTmpSel.Adjust( pEditEngine->GetEditDoc() );
@ -601,7 +601,7 @@ void ImpEditView::DrawSelectionXOR( EditSelection aTmpSel, vcl::Region* pRegion,
aTmpRect.SetRight(aLineXPosStartEnd.Max());
aTmpRect.Move(aLineOffset.Width(), 0);
ImplDrawHighlightRect(rTarget, aTmpRect.TopLeft(), aTmpRect.BottomRight(),
pPolyPoly.get());
pPolyPoly ? &*pPolyPoly : nullptr);
}
else
{
@ -627,7 +627,7 @@ void ImpEditView::DrawSelectionXOR( EditSelection aTmpSel, vcl::Region* pRegion,
aTmpRect.Move(aLineOffset.Width(), 0);
ImplDrawHighlightRect(rTarget, aTmpRect.TopLeft(), aTmpRect.BottomRight(),
pPolyPoly.get());
pPolyPoly ? &*pPolyPoly : nullptr);
nTmpStartIndex = nTmpEndIndex;
}
}

View file

@ -307,7 +307,7 @@ private:
return mpEditViewCallbacks;
}
void lokSelectionCallback(const std::unique_ptr<tools::PolyPolygon> &pPolyPoly, bool bStartHandleVisible, bool bEndHandleVisible);
void lokSelectionCallback(const std::optional<tools::PolyPolygon> &pPolyPoly, bool bStartHandleVisible, bool bEndHandleVisible);
void setEditViewCallbacks(EditViewCallbacks* pEditViewCallbacks)
{

View file

@ -54,7 +54,7 @@ TextRanger::TextRanger( const basegfx::B2DPolyPolygon& rPolyPolygon,
if( pLinePolyPolygon )
{
nCount = pLinePolyPolygon->count();
mpLinePolyPolygon.reset( new tools::PolyPolygon() );
mpLinePolyPolygon = tools::PolyPolygon(nCount);
for(sal_uInt32 i(0); i < nCount; i++)
{
@ -64,7 +64,7 @@ TextRanger::TextRanger( const basegfx::B2DPolyPolygon& rPolyPolygon,
}
}
else
mpLinePolyPolygon = nullptr;
mpLinePolyPolygon.reset();
}
@ -647,7 +647,7 @@ std::deque<tools::Long>* TextRanger::GetTextRanges( const Range& rRange )
SvxBoundArgs aArg( this, &(rngCache.results), rRange );
aArg.Calc( maPolyPolygon );
if( mpLinePolyPolygon )
aArg.Concat( mpLinePolyPolygon.get() );
aArg.Concat( &*mpLinePolyPolygon );
//Add new result to the cache
mRangeCache.push_back(std::move(rngCache));
if (mRangeCache.size() > nCacheSize)

View file

@ -42,7 +42,7 @@ class EDITENG_DLLPUBLIC TextRanger
};
std::deque<RangeCacheItem> mRangeCache; //!< Cached range calculations.
tools::PolyPolygon maPolyPolygon; // Surface polygon
std::unique_ptr<tools::PolyPolygon> mpLinePolyPolygon; // Line polygon
std::optional<tools::PolyPolygon> mpLinePolyPolygon; // Line polygon
mutable std::optional<tools::Rectangle> mxBound; // Comprehensive rectangle
sal_uInt16 nCacheSize; // Cache-Size
sal_uInt16 nRight; // Distance Contour-Text

View file

@ -19,11 +19,11 @@
#ifndef INCLUDED_SW_INC_NDNOTXT_HXX
#define INCLUDED_SW_INC_NDNOTXT_HXX
#include <memory>
#include <optional>
#include <tools/poly.hxx>
#include "node.hxx"
class Size;
namespace tools { class PolyPolygon; }
// SwNoTextNode
@ -32,12 +32,12 @@ class SW_DLLPUBLIC SwNoTextNode : public SwContentNode
friend class SwNodes;
friend class SwNoTextFrame;
std::unique_ptr<tools::PolyPolygon> m_pContour;
mutable std::optional<tools::PolyPolygon> m_pContour;
bool m_bAutomaticContour : 1; // automatic contour polygon, not manipulated
bool m_bContourMapModeValid : 1; // contour map mode is not the graphics's
mutable bool m_bContourMapModeValid : 1; // contour map mode is not the graphics's
// preferred map mode, but either
// MM100 or pixel
bool m_bPixelContour : 1; // contour map mode is invalid and pixel.
mutable bool m_bPixelContour : 1; // contour map mode is invalid and pixel.
// Creates for all derivations an AttrSet with ranges for frame- and
// graphics-attributes (only called by SwContentNode).
@ -70,7 +70,7 @@ public:
void SetContour( const tools::PolyPolygon *pPoly,
bool bAutomatic = false );
const tools::PolyPolygon *HasContour() const;
bool HasContour_() const { return m_pContour!=nullptr; };
bool HasContour_() const { return bool(m_pContour); };
void GetContour( tools::PolyPolygon &rPoly ) const;
void CreateContour();

View file

@ -85,7 +85,7 @@ bool SwNoTextNode::SavePersistentData()
void SwNoTextNode::SetContour( const tools::PolyPolygon *pPoly, bool bAutomatic )
{
if ( pPoly )
m_pContour.reset( new tools::PolyPolygon( *pPoly ) );
m_pContour = *pPoly;
else
m_pContour.reset();
m_bAutomaticContour = bAutomatic;
@ -96,7 +96,7 @@ void SwNoTextNode::SetContour( const tools::PolyPolygon *pPoly, bool bAutomatic
void SwNoTextNode::CreateContour()
{
OSL_ENSURE( !m_pContour, "Contour available." );
m_pContour.reset( new tools::PolyPolygon(SvxContourDlg::CreateAutoContour(GetGraphic())) );
m_pContour = SvxContourDlg::CreateAutoContour(GetGraphic());
m_bAutomaticContour = true;
m_bContourMapModeValid = true;
m_bPixelContour = false;
@ -154,11 +154,11 @@ const tools::PolyPolygon *SwNoTextNode::HasContour() const
}
}
}
const_cast<SwNoTextNode *>(this)->m_bContourMapModeValid = true;
const_cast<SwNoTextNode *>(this)->m_bPixelContour = false;
m_bContourMapModeValid = true;
m_bPixelContour = false;
}
return m_pContour.get();
return m_pContour ? &*m_pContour : nullptr;
}
void SwNoTextNode::GetContour( tools::PolyPolygon &rPoly ) const
@ -170,7 +170,7 @@ void SwNoTextNode::GetContour( tools::PolyPolygon &rPoly ) const
void SwNoTextNode::SetContourAPI( const tools::PolyPolygon *pPoly )
{
if ( pPoly )
m_pContour.reset( new tools::PolyPolygon( *pPoly ) );
m_pContour = *pPoly;
else
m_pContour.reset();
m_bContourMapModeValid = false;

View file

@ -457,7 +457,7 @@ void OutputDevice::DrawComplexGradient( const tools::Rectangle& rRect,
// Also for printers always use PolyPolygon, as not all printers
// can print polygons on top of each other.
std::unique_ptr<tools::PolyPolygon> xPolyPoly;
std::optional<tools::PolyPolygon> xPolyPoly;
tools::Rectangle aRect;
Point aCenter;
Color aStartCol( rGradient.GetStartColor() );
@ -476,7 +476,7 @@ void OutputDevice::DrawComplexGradient( const tools::Rectangle& rRect,
rGradient.GetBoundRect( rRect, aRect, aCenter );
if ( UsePolyPolygonForComplexGradient() )
xPolyPoly.reset(new tools::PolyPolygon( 2 ));
xPolyPoly = tools::PolyPolygon( 2 );
tools::Long nStepCount = GetGradientSteps( rGradient, rRect, false/*bMtf*/, true/*bComplex*/ );
@ -807,7 +807,7 @@ void OutputDevice::DrawComplexGradientToMetafile( const tools::Rectangle& rRect,
// Also for printers always use PolyPolygon, as not all printers
// can print polygons on top of each other.
std::unique_ptr<tools::PolyPolygon> xPolyPoly;
std::optional<tools::PolyPolygon> xPolyPoly;
tools::Rectangle aRect;
Point aCenter;
Color aStartCol( rGradient.GetStartColor() );
@ -825,7 +825,7 @@ void OutputDevice::DrawComplexGradientToMetafile( const tools::Rectangle& rRect,
rGradient.GetBoundRect( rRect, aRect, aCenter );
xPolyPoly.reset(new tools::PolyPolygon( 2 ));
xPolyPoly = tools::PolyPolygon( 2 );
// last parameter - true if complex gradient, false if linear
tools::Long nStepCount = GetGradientSteps( rGradient, rRect, true, true );