From e8aea2a4f660cff901c56bcbd2a88377482f4609 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 28 Jun 2022 12:28:49 +0200 Subject: tdf#134328 use more make_shared one less allocation this way Change-Id: Id5fbd414837d7521306dd188306c4e60394307e8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136566 Tested-by: Jenkins Reviewed-by: Noel Grandin --- vcl/source/gdi/region.cxx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'vcl/source') diff --git a/vcl/source/gdi/region.cxx b/vcl/source/gdi/region.cxx index 576ae0eb2e10..ea03d8a0787c 100644 --- a/vcl/source/gdi/region.cxx +++ b/vcl/source/gdi/region.cxx @@ -316,7 +316,8 @@ Region::Region(bool bIsNull) Region::Region(const tools::Rectangle& rRect) : mbIsNull(false) { - mpRegionBand.reset(rRect.IsEmpty() ? nullptr : new RegionBand(rRect)); + if (!rRect.IsEmpty()) + mpRegionBand = std::make_shared(rRect); } Region::Region(const tools::Polygon& rPolygon) @@ -437,12 +438,12 @@ void vcl::Region::Move( tools::Long nHorzMove, tools::Long nVertMove ) } else if(getRegionBand()) { - RegionBand* pNew = new RegionBand(*getRegionBand()); + std::shared_ptr pNew = std::make_shared(*getRegionBand()); pNew->Move(nHorzMove, nVertMove); mpB2DPolyPolygon.reset(); mpPolyPolygon.reset(); - mpRegionBand.reset(pNew); + mpRegionBand = std::move(pNew); } else { @@ -490,12 +491,12 @@ void vcl::Region::Scale( double fScaleX, double fScaleY ) } else if(getRegionBand()) { - RegionBand* pNew = new RegionBand(*getRegionBand()); + std::shared_ptr pNew = std::make_shared(*getRegionBand()); pNew->Scale(fScaleX, fScaleY); mpB2DPolyPolygon.reset(); mpPolyPolygon.reset(); - mpRegionBand.reset(pNew); + mpRegionBand = std::move(pNew); } else { @@ -1447,7 +1448,10 @@ Region& vcl::Region::operator=( const tools::Rectangle& rRect ) { mpB2DPolyPolygon.reset(); mpPolyPolygon.reset(); - mpRegionBand.reset(rRect.IsEmpty() ? nullptr : new RegionBand(rRect)); + if (!rRect.IsEmpty()) + mpRegionBand = std::make_shared(rRect); + else + mpRegionBand.reset(); mbIsNull = false; return *this; -- cgit