[Libreoffice-commits] core.git: include/vcl vcl/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Sun Aug 22 12:46:13 UTC 2021


 include/vcl/region.hxx    |   15 +++++---------
 vcl/source/gdi/region.cxx |   48 +++++++++++++++++++++++++++++++---------------
 2 files changed, 39 insertions(+), 24 deletions(-)

New commits:
commit d2bf9e56310fe40eac700afa974483d704e4c70a
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Sat Aug 21 20:29:48 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun Aug 22 14:45:33 2021 +0200

    no need to use shared_ptr for these fields in Region
    
    they are already COW types
    
    Change-Id: I8b673304452cc50c581be03a605efafa77175b2e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120829
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/vcl/region.hxx b/include/vcl/region.hxx
index e6c7448e36c1..cf48fbdff6e1 100644
--- a/include/vcl/region.hxx
+++ b/include/vcl/region.hxx
@@ -21,17 +21,14 @@
 #define INCLUDED_VCL_REGION_HXX
 
 #include <tools/gen.hxx>
+#include <tools/poly.hxx>
 #include <vcl/dllapi.h>
 #include <basegfx/polygon/b2dpolypolygon.hxx>
 #include <memory>
+#include <optional>
 
 class RegionBand;
 
-namespace tools {
-    class Polygon;
-    class PolyPolygon;
-}
-
 namespace vcl { class Window; }
 class OutputDevice;
 class Bitmap;
@@ -48,9 +45,9 @@ private:
     friend class ::Bitmap;
 
     // possible contents
-    std::shared_ptr< basegfx::B2DPolyPolygon >
+    std::optional< basegfx::B2DPolyPolygon >
                                 mpB2DPolyPolygon;
-    std::shared_ptr< tools::PolyPolygon >
+    std::optional< tools::PolyPolygon >
                                 mpPolyPolygon;
     std::shared_ptr< RegionBand >
                                 mpRegionBand;
@@ -76,8 +73,8 @@ public:
     ~Region();
 
     // direct access to contents
-    const basegfx::B2DPolyPolygon* getB2DPolyPolygon() const { return mpB2DPolyPolygon.get(); }
-    const tools::PolyPolygon* getPolyPolygon() const { return mpPolyPolygon.get(); }
+    const std::optional<basegfx::B2DPolyPolygon>& getB2DPolyPolygon() const { return mpB2DPolyPolygon; }
+    const std::optional<tools::PolyPolygon>& getPolyPolygon() const { return mpPolyPolygon; }
     const RegionBand* getRegionBand() const { return mpRegionBand.get(); }
 
     // access with converters, the asked data will be created from the most
diff --git a/vcl/source/gdi/region.cxx b/vcl/source/gdi/region.cxx
index 0f80a717c5f6..2dbea8db1f0d 100644
--- a/vcl/source/gdi/region.cxx
+++ b/vcl/source/gdi/region.cxx
@@ -396,7 +396,7 @@ void vcl::Region::ImplCreatePolyPolyRegion( const tools::PolyPolygon& rPolyPoly
     }
     else
     {
-        mpPolyPolygon = std::make_shared<tools::PolyPolygon>(rPolyPoly);
+        mpPolyPolygon = rPolyPoly;
     }
 
     mbIsNull = false;
@@ -406,7 +406,7 @@ void vcl::Region::ImplCreatePolyPolyRegion( const basegfx::B2DPolyPolygon& rPoly
 {
     if(rPolyPoly.count() && !rPolyPoly.getB2DRange().isEmpty())
     {
-        mpB2DPolyPolygon = std::make_shared<basegfx::B2DPolyPolygon>(rPolyPoly);
+        mpB2DPolyPolygon = rPolyPoly;
         mbIsNull = false;
     }
 }
@@ -430,7 +430,10 @@ void vcl::Region::Move( tools::Long nHorzMove, tools::Long nVertMove )
         basegfx::B2DPolyPolygon aPoly(*getB2DPolyPolygon());
 
         aPoly.transform(basegfx::utils::createTranslateB2DHomMatrix(nHorzMove, nVertMove));
-        mpB2DPolyPolygon.reset(aPoly.count() ? new basegfx::B2DPolyPolygon(aPoly) : nullptr);
+        if (aPoly.count())
+            mpB2DPolyPolygon = aPoly;
+        else
+            mpB2DPolyPolygon.reset();
         mpPolyPolygon.reset();
         mpRegionBand.reset();
     }
@@ -440,7 +443,10 @@ void vcl::Region::Move( tools::Long nHorzMove, tools::Long nVertMove )
 
         aPoly.Move(nHorzMove, nVertMove);
         mpB2DPolyPolygon.reset();
-        mpPolyPolygon.reset(aPoly.Count() ? new tools::PolyPolygon(aPoly) : nullptr);
+        if (aPoly.Count())
+            mpPolyPolygon = aPoly;
+        else
+            mpPolyPolygon.reset();
         mpRegionBand.reset();
     }
     else if(getRegionBand())
@@ -477,7 +483,10 @@ void vcl::Region::Scale( double fScaleX, double fScaleY )
         basegfx::B2DPolyPolygon aPoly(*getB2DPolyPolygon());
 
         aPoly.transform(basegfx::utils::createScaleB2DHomMatrix(fScaleX, fScaleY));
-        mpB2DPolyPolygon.reset(aPoly.count() ? new basegfx::B2DPolyPolygon(aPoly) : nullptr);
+        if (aPoly.count())
+            mpB2DPolyPolygon = aPoly;
+        else
+            mpB2DPolyPolygon.reset();
         mpPolyPolygon.reset();
         mpRegionBand.reset();
     }
@@ -487,7 +496,10 @@ void vcl::Region::Scale( double fScaleX, double fScaleY )
 
         aPoly.Scale(fScaleX, fScaleY);
         mpB2DPolyPolygon.reset();
-        mpPolyPolygon.reset(aPoly.Count() ? new tools::PolyPolygon(aPoly) : nullptr);
+        if (aPoly.Count())
+            mpPolyPolygon = aPoly;
+        else
+            mpPolyPolygon.reset();
         mpRegionBand.reset();
     }
     else if(getRegionBand())
@@ -619,7 +631,10 @@ void vcl::Region::Intersect( const tools::Rectangle& rRect )
                     true,
                     false));
 
-            mpB2DPolyPolygon.reset(aPoly.count() ? new basegfx::B2DPolyPolygon(aPoly) : nullptr);
+            if (aPoly.count())
+                mpB2DPolyPolygon = aPoly;
+            else
+                mpB2DPolyPolygon.reset();
             mpPolyPolygon.reset();
             mpRegionBand.reset();
         }
@@ -633,7 +648,10 @@ void vcl::Region::Intersect( const tools::Rectangle& rRect )
             aPoly.Clip(rRect);
 
             mpB2DPolyPolygon.reset();
-            mpPolyPolygon.reset(aPoly.Count() ? new tools::PolyPolygon(aPoly) : nullptr);
+            if (aPoly.Count())
+                mpPolyPolygon = aPoly;
+            else
+                mpPolyPolygon.reset();
             mpRegionBand.reset();
         }
 
@@ -1269,7 +1287,7 @@ tools::PolyPolygon vcl::Region::GetAsPolyPolygon() const
     {
         // the polygon needs to be converted, buffer the down conversion
         const tools::PolyPolygon aPolyPolgon(*getB2DPolyPolygon());
-        const_cast< vcl::Region* >(this)->mpPolyPolygon = std::make_shared<tools::PolyPolygon>(aPolyPolgon);
+        const_cast< vcl::Region* >(this)->mpPolyPolygon = aPolyPolgon;
 
         return *getPolyPolygon();
     }
@@ -1278,7 +1296,7 @@ tools::PolyPolygon vcl::Region::GetAsPolyPolygon() const
     {
         // the BandRegion needs to be converted, buffer the conversion
         const tools::PolyPolygon aPolyPolgon(ImplCreatePolyPolygonFromRegionBand());
-        const_cast< vcl::Region* >(this)->mpPolyPolygon = std::make_shared<tools::PolyPolygon>(aPolyPolgon);
+        const_cast< vcl::Region* >(this)->mpPolyPolygon = aPolyPolgon;
 
         return *getPolyPolygon();
     }
@@ -1297,7 +1315,7 @@ basegfx::B2DPolyPolygon vcl::Region::GetAsB2DPolyPolygon() const
     {
         // the polygon needs to be converted, buffer the up conversion. This will be preferred from now.
         const basegfx::B2DPolyPolygon aB2DPolyPolygon(getPolyPolygon()->getB2DPolyPolygon());
-        const_cast< vcl::Region* >(this)->mpB2DPolyPolygon = std::make_shared<basegfx::B2DPolyPolygon>(aB2DPolyPolygon);
+        const_cast< vcl::Region* >(this)->mpB2DPolyPolygon = aB2DPolyPolygon;
 
         return *getB2DPolyPolygon();
     }
@@ -1306,7 +1324,7 @@ basegfx::B2DPolyPolygon vcl::Region::GetAsB2DPolyPolygon() const
     {
         // the BandRegion needs to be converted, buffer the conversion
         const basegfx::B2DPolyPolygon aB2DPolyPolygon(ImplCreateB2DPolyPolygonFromRegionBand());
-        const_cast< vcl::Region* >(this)->mpB2DPolyPolygon = std::make_shared<basegfx::B2DPolyPolygon>(aB2DPolyPolygon);
+        const_cast< vcl::Region* >(this)->mpB2DPolyPolygon = aB2DPolyPolygon;
 
         return *getB2DPolyPolygon();
     }
@@ -1565,9 +1583,9 @@ SvStream& ReadRegion(SvStream& rIStrm, vcl::Region& rRegion)
 
                 if (bHasPolyPolygon)
                 {
-                    std::shared_ptr<tools::PolyPolygon> xNewPoly = std::make_shared<tools::PolyPolygon>();
-                    ReadPolyPolygon(rIStrm, *xNewPoly);
-                    rRegion.mpPolyPolygon = xNewPoly;
+                    tools::PolyPolygon aNewPoly;
+                    ReadPolyPolygon(rIStrm, aNewPoly);
+                    rRegion.mpPolyPolygon = aNewPoly;
                 }
             }
 


More information about the Libreoffice-commits mailing list