[Libreoffice-commits] core.git: 2 commits - svx/inc svx/source

Noel Grandin noel.grandin at collabora.co.uk
Mon Mar 5 06:28:23 UTC 2018


 svx/inc/xpolyimp.hxx          |    2 +-
 svx/source/xml/xmlgrhlp.cxx   |   24 +++++++++++-------------
 svx/source/xoutdev/_xpoly.cxx |   32 ++++++++++++++++----------------
 3 files changed, 28 insertions(+), 30 deletions(-)

New commits:
commit 151bd68854795b3588f01083cf3ca75826c6df1f
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Feb 28 15:04:18 2018 +0200

    loplugin:useuniqueptr in ImpXPolygon
    
    Change-Id: I5bb3f0661f5d62527bb5a8d24035c46a6a11e185
    Reviewed-on: https://gerrit.libreoffice.org/50691
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/svx/inc/xpolyimp.hxx b/svx/inc/xpolyimp.hxx
index fd0fe2905d8b..4b73dd6fe556 100644
--- a/svx/inc/xpolyimp.hxx
+++ b/svx/inc/xpolyimp.hxx
@@ -29,7 +29,7 @@ class Point;
 class ImpXPolygon
 {
 public:
-    Point*              pPointAry;
+    std::unique_ptr<Point[]> pPointAry;
     std::unique_ptr<PolyFlags[]>
                         pFlagAry;
     Point*              pOldPointAry;
diff --git a/svx/source/xoutdev/_xpoly.cxx b/svx/source/xoutdev/_xpoly.cxx
index 05fe65b17d89..a4024a061954 100644
--- a/svx/source/xoutdev/_xpoly.cxx
+++ b/svx/source/xoutdev/_xpoly.cxx
@@ -65,13 +65,13 @@ ImpXPolygon::ImpXPolygon( const ImpXPolygon& rImpXPoly )
 
     // copy
     nPoints = rImpXPoly.nPoints;
-    memcpy( pPointAry, rImpXPoly.pPointAry, nSize*sizeof( Point ) );
+    memcpy( pPointAry.get(), rImpXPoly.pPointAry.get(), nSize*sizeof( Point ) );
     memcpy( pFlagAry.get(), rImpXPoly.pFlagAry.get(), nSize );
 }
 
 ImpXPolygon::~ImpXPolygon()
 {
-    delete[] pPointAry;
+    pPointAry.reset();
     if ( bDeleteOldPoints )
     {
         delete[] pOldPointAry;
@@ -83,7 +83,7 @@ bool ImpXPolygon::operator==(const ImpXPolygon& rImpXPoly) const
 {
     return nPoints==rImpXPoly.nPoints &&
            (nPoints==0 ||
-            (memcmp(pPointAry, rImpXPoly.pPointAry, nPoints*sizeof(Point))==0 &&
+            (memcmp(pPointAry.get(), rImpXPoly.pPointAry.get(), nPoints*sizeof(Point))==0 &&
              memcmp(pFlagAry.get(), rImpXPoly.pFlagAry.get(), nPoints)==0));
 }
 
@@ -104,7 +104,7 @@ void ImpXPolygon::Resize( sal_uInt16 nNewSize, bool bDeletePoints )
     sal_uInt16  nOldSize     = nSize;
 
     CheckPointDelete();
-    pOldPointAry = pPointAry;
+    pOldPointAry = pPointAry.release();
 
     // Round the new size to a multiple of nResize, if
     // the object was not newly created (nSize != 0)
@@ -115,7 +115,7 @@ void ImpXPolygon::Resize( sal_uInt16 nNewSize, bool bDeletePoints )
     }
     // create point array
     nSize     = nNewSize;
-    pPointAry = new Point[ nSize ];
+    pPointAry.reset( new Point[ nSize ] );
 
     // create flag array
     pFlagAry.reset( new PolyFlags[ nSize ] );
@@ -126,12 +126,12 @@ void ImpXPolygon::Resize( sal_uInt16 nNewSize, bool bDeletePoints )
     {
         if( nOldSize < nSize )
         {
-            memcpy( pPointAry, pOldPointAry, nOldSize*sizeof( Point ) );
+            memcpy( pPointAry.get(), pOldPointAry, nOldSize*sizeof( Point ) );
             memcpy( pFlagAry.get(),  pOldFlagAry, nOldSize );
         }
         else
         {
-            memcpy( pPointAry, pOldPointAry, nSize*sizeof( Point ) );
+            memcpy( pPointAry.get(), pOldPointAry, nSize*sizeof( Point ) );
             memcpy( pFlagAry.get(), pOldFlagAry, nSize );
 
             // adjust number of valid points
@@ -168,7 +168,7 @@ void ImpXPolygon::InsertSpace( sal_uInt16 nPos, sal_uInt16 nCount )
                  nMove * sizeof(Point) );
         memmove( &pFlagAry[nPos+nCount], &pFlagAry[nPos], nMove );
     }
-    std::fill(pPointAry + nPos, pPointAry + nPos + nCount, Point());
+    std::fill(pPointAry.get() + nPos, pPointAry.get() + nPos + nCount, Point());
     memset( &pFlagAry [nPos], 0, nCount );
 
     nPoints = nPoints + nCount;
@@ -188,7 +188,7 @@ void ImpXPolygon::Remove( sal_uInt16 nPos, sal_uInt16 nCount )
                      nMove * sizeof(Point) );
             memmove( &pFlagAry[nPos], &pFlagAry[nPos+nCount], nMove );
         }
-        std::fill(pPointAry + (nPoints - nCount), pPointAry + nPoints, Point());
+        std::fill(pPointAry.get() + (nPoints - nCount), pPointAry.get() + nPoints, Point());
         memset( &pFlagAry [nPoints - nCount], 0, nCount );
         nPoints = nPoints - nCount;
     }
@@ -348,7 +348,7 @@ void XPolygon::SetPointCount( sal_uInt16 nPoints )
     {
         sal_uInt16 nSize = pImpXPolygon->nPoints - nPoints;
         std::fill(
-            pImpXPolygon->pPointAry + nPoints, pImpXPolygon->pPointAry + nPoints + nSize, Point());
+            pImpXPolygon->pPointAry.get() + nPoints, pImpXPolygon->pPointAry.get() + nPoints + nSize, Point());
         memset( &pImpXPolygon->pFlagAry [nPoints], 0, nSize );
     }
     pImpXPolygon->nPoints = nPoints;
@@ -383,7 +383,7 @@ void XPolygon::Insert( sal_uInt16 nPos, const XPolygon& rXPoly )
     pImpXPolygon->InsertSpace( nPos, nPoints );
 
     memcpy( &(pImpXPolygon->pPointAry[nPos]),
-            rXPoly.pImpXPolygon->pPointAry,
+            rXPoly.pImpXPolygon->pPointAry.get(),
             nPoints*sizeof( Point ) );
     memcpy( &(pImpXPolygon->pFlagAry[nPos]),
             rXPoly.pImpXPolygon->pFlagAry.get(),
@@ -516,7 +516,7 @@ double XPolygon::CalcDistance(sal_uInt16 nP1, sal_uInt16 nP2)
 
 void XPolygon::SubdivideBezier(sal_uInt16 nPos, bool bCalcFirst, double fT)
 {
-    Point*  pPoints = pImpXPolygon->pPointAry;
+    Point*  pPoints = pImpXPolygon->pPointAry.get();
     double  fT2 = fT * fT;
     double  fT3 = fT * fT2;
     double  fU = 1.0 - fT;
@@ -565,7 +565,7 @@ void XPolygon::GenBezArc(const Point& rCenter, long nRx, long nRy,
                          long nXHdl, long nYHdl, sal_uInt16 nStart, sal_uInt16 nEnd,
                          sal_uInt16 nQuad, sal_uInt16 nFirst)
 {
-    Point* pPoints = pImpXPolygon->pPointAry;
+    Point* pPoints = pImpXPolygon->pPointAry.get();
     pPoints[nFirst  ] = rCenter;
     pPoints[nFirst+3] = rCenter;
 
@@ -647,7 +647,7 @@ void XPolygon::CalcSmoothJoin(sal_uInt16 nCenter, sal_uInt16 nDrag, sal_uInt16 n
         nDrag = nPnt;
         nPnt = nTmp;
     }
-    Point*  pPoints = pImpXPolygon->pPointAry;
+    Point*  pPoints = pImpXPolygon->pPointAry.get();
     Point   aDiff   = pPoints[nDrag] - pPoints[nCenter];
     double  fDiv    = CalcDistance(nCenter, nDrag);
 
@@ -703,7 +703,7 @@ void XPolygon::PointsToBezier(sal_uInt16 nFirst)
     double  fX0, fY0, fX1, fY1, fX2, fY2, fX3, fY3;
     double  fTx1, fTx2, fTy1, fTy2;
     double  fT1, fU1, fT2, fU2, fV;
-    Point*  pPoints = pImpXPolygon->pPointAry;
+    Point*  pPoints = pImpXPolygon->pPointAry.get();
 
     if ( nFirst > pImpXPolygon->nPoints - 4 || IsControl(nFirst) ||
          IsControl(nFirst+1) || IsControl(nFirst+2) || IsControl(nFirst+3) )
@@ -842,7 +842,7 @@ basegfx::B2DPolygon XPolygon::getB2DPolygon() const
     // #i74631# use tools Polygon class for conversion to not have the code doubled
     // here. This needs one more conversion but avoids different convertors in
     // the long run
-    const tools::Polygon aSource(GetPointCount(), pImpXPolygon->pPointAry, pImpXPolygon->pFlagAry.get());
+    const tools::Polygon aSource(GetPointCount(), pImpXPolygon->pPointAry.get(), pImpXPolygon->pFlagAry.get());
 
     return aSource.getB2DPolygon();
 }
commit 3a561cac82bcccda4f5685645f865e3176e6a005
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Feb 28 14:56:04 2018 +0200

    loplugin:useuniqueptr in SvXMLGraphicOutputStream
    
    Change-Id: I44a5dbb244301181019ad09aebed46b0054c3b4b
    Reviewed-on: https://gerrit.libreoffice.org/50690
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx
index ddac8dbbe812..f8f690747959 100644
--- a/svx/source/xml/xmlgrhlp.cxx
+++ b/svx/source/xml/xmlgrhlp.cxx
@@ -358,11 +358,11 @@ private:
 
 private:
 
-    ::utl::TempFile*                mpTmp;
-    SvStream*                       mpOStm;
-    Reference< XOutputStream >      mxStmWrapper;
-    std::unique_ptr<GraphicObject>  mxGrfObj;
-    bool                        mbClosed;
+    std::unique_ptr<::utl::TempFile> mpTmp;
+    std::unique_ptr<SvStream>        mpOStm;
+    Reference< XOutputStream >       mxStmWrapper;
+    std::unique_ptr<GraphicObject>   mxGrfObj;
+    bool                             mbClosed;
 
 public:
 
@@ -383,7 +383,7 @@ SvXMLGraphicOutputStream::SvXMLGraphicOutputStream()
 {
     mpTmp->EnableKillingFile();
 
-    mpOStm = ::utl::UcbStreamHelper::CreateStream( mpTmp->GetURL(), StreamMode::WRITE | StreamMode::TRUNC );
+    mpOStm.reset( ::utl::UcbStreamHelper::CreateStream( mpTmp->GetURL(), StreamMode::WRITE | StreamMode::TRUNC ) );
 
     if( mpOStm )
         mxStmWrapper = new ::utl::OOutputStreamWrapper( *mpOStm );
@@ -391,8 +391,8 @@ SvXMLGraphicOutputStream::SvXMLGraphicOutputStream()
 
 SvXMLGraphicOutputStream::~SvXMLGraphicOutputStream()
 {
-    delete mpTmp;
-    delete mpOStm;
+    mpTmp.reset();
+    mpOStm.reset();
 }
 
 void SAL_CALL SvXMLGraphicOutputStream::writeBytes( const Sequence< sal_Int8 >& rData )
@@ -484,11 +484,9 @@ Graphic SvXMLGraphicOutputStream::GetGraphic()
 
     if (aGraphic.GetType() != GraphicType::NONE)
     {
-        delete mpOStm;
-        mpOStm = nullptr;
-        delete mpTmp;
-        mpTmp = nullptr;
-    }
+        mpOStm.reset();
+        mpTmp.reset();
+     }
     return aGraphic;
 }
 


More information about the Libreoffice-commits mailing list