[Libreoffice-commits] core.git: 2 commits - chart2/source hwpfilter/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Aug 15 06:41:52 UTC 2018


 chart2/source/view/charttypes/BarPositionHelper.cxx |    6 ++--
 chart2/source/view/charttypes/BarPositionHelper.hxx |    2 -
 chart2/source/view/charttypes/VSeriesPlotter.cxx    |   11 ++-----
 chart2/source/view/inc/PlottingPositionHelper.hxx   |    6 ++--
 chart2/source/view/inc/VSeriesPlotter.hxx           |    2 -
 chart2/source/view/main/PlottingPositionHelper.cxx  |   15 +++++-----
 hwpfilter/source/cspline.cxx                        |    4 --
 hwpfilter/source/solver.cxx                         |   28 +++-----------------
 hwpfilter/source/solver.h                           |    5 +--
 9 files changed, 26 insertions(+), 53 deletions(-)

New commits:
commit 13ec3a1d80df070fff0227b089c4e9d29d7f06cc
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Aug 13 16:17:08 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Aug 15 08:41:32 2018 +0200

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

diff --git a/hwpfilter/source/cspline.cxx b/hwpfilter/source/cspline.cxx
index 32041163e00b..a61104f5e9ac 100644
--- a/hwpfilter/source/cspline.cxx
+++ b/hwpfilter/source/cspline.cxx
@@ -119,7 +119,7 @@ void PeriodicSpline (int N, const double* x, const double* a, double*& b, double
   for (i = 0; i < N; i++)
     h[i] = x[i+1]-x[i];
 
-  double** mat = mgcLinearSystemD::NewMatrix(N+1);  // guaranteed to be zeroed memory
+  std::unique_ptr<std::unique_ptr<double[]>[]> mat = mgcLinearSystemD::NewMatrix(N+1);  // guaranteed to be zeroed memory
   c = mgcLinearSystemD::NewVector(N+1);   // guaranteed to be zeroed memory
 
   // c[0] - c[N] = 0
@@ -155,8 +155,6 @@ void PeriodicSpline (int N, const double* x, const double* a, double*& b, double
     b[i] = (a[i+1]-a[i])/h[i] - oneThird*(c[i+1]+2.0f*c[i])*h[i];
     d[i] = oneThird*(c[i+1]-c[i])/h[i];
   }
-
-  mgcLinearSystemD::DeleteMatrix(N+1,mat);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/solver.cxx b/hwpfilter/source/solver.cxx
index d1c76b8cd916..323eaa2af068 100644
--- a/hwpfilter/source/solver.cxx
+++ b/hwpfilter/source/solver.cxx
@@ -22,35 +22,19 @@
 #include "solver.h"
 
 
-double** mgcLinearSystemD::NewMatrix (int N)
+std::unique_ptr<std::unique_ptr<double[]>[]> mgcLinearSystemD::NewMatrix (int N)
 {
-  double** A = new double*[N];
-  if ( !A )
-    return nullptr;
+  std::unique_ptr<std::unique_ptr<double[]>[]> A(new std::unique_ptr<double[]>);
 
   for (int row = 0; row < N; row++)
   {
-    A[row] = new double[N];
-    if ( !A[row] )
-    {
-      for (int i = 0; i < row; i++)
-    delete[] A[i];
-      delete[] A;
-      return nullptr;
-    }
+    A[row].reset(new double[N]);
     for (int col = 0; col < N; col++)
       A[row][col] = 0;
   }
   return A;
 }
 
-void mgcLinearSystemD::DeleteMatrix (int N, double** A)
-{
-  for (int row = 0; row < N; row++)
-    delete[] A[row];
-  delete[] A;
-}
-
 double* mgcLinearSystemD::NewVector (int N)
 {
   double* B = new double[N];
@@ -62,7 +46,7 @@ double* mgcLinearSystemD::NewVector (int N)
   return B;
 }
 
-bool mgcLinearSystemD::Solve (int n, double** a, double* b)
+bool mgcLinearSystemD::Solve (int n, std::unique_ptr<std::unique_ptr<double[]>[]>& a, double* b)
 {
   std::unique_ptr<int[]> indxc( new int[n] );
   if ( !indxc )
@@ -113,9 +97,7 @@ bool mgcLinearSystemD::Solve (int n, double** a, double* b)
 
     if ( irow != icol )
     {
-      double* rowptr = a[irow];
-      a[irow] = a[icol];
-      a[icol] = rowptr;
+      std::swap(a[irow], a[icol]);
 
       save = b[irow];
       b[irow] = b[icol];
diff --git a/hwpfilter/source/solver.h b/hwpfilter/source/solver.h
index ea3295bad9d4..0da10ac72ae8 100644
--- a/hwpfilter/source/solver.h
+++ b/hwpfilter/source/solver.h
@@ -23,11 +23,10 @@
 class mgcLinearSystemD
 {
 public:
-  static double** NewMatrix (int N);
-  static void DeleteMatrix (int N, double** A);
+  static std::unique_ptr<std::unique_ptr<double[]>[]> NewMatrix (int N);
   static double* NewVector (int N);
 
-  static bool Solve (int N, double** A, double* b);
+  static bool Solve (int N, std::unique_ptr<std::unique_ptr<double[]>[]>& A, double* b);
   // Input:
   //     A[N][N] coefficient matrix, entries are A[row][col]
   //     b[N] vector, entries are b[row]
commit 6536083617f5043752f047fff7a8641873a69d4c
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Aug 13 16:15:53 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Aug 15 08:41:25 2018 +0200

    pass PlottingPositionHelper around by std::unique_ptr
    
    Change-Id: I2bcfeb1e670bc75f093a05e7d5bfb0be09235052
    Reviewed-on: https://gerrit.libreoffice.org/59023
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/chart2/source/view/charttypes/BarPositionHelper.cxx b/chart2/source/view/charttypes/BarPositionHelper.cxx
index cd5e215fcb0d..45565989f9d7 100644
--- a/chart2/source/view/charttypes/BarPositionHelper.cxx
+++ b/chart2/source/view/charttypes/BarPositionHelper.cxx
@@ -22,6 +22,7 @@
 #include <ViewDefines.hxx>
 #include <CommonConverters.hxx>
 #include <DateHelper.hxx>
+#include <o3tl/make_unique.hxx>
 #include <com/sun/star/chart/TimeUnit.hpp>
 
 namespace chart
@@ -46,10 +47,9 @@ BarPositionHelper::~BarPositionHelper()
 {
 }
 
-PlottingPositionHelper* BarPositionHelper::clone() const
+std::unique_ptr<PlottingPositionHelper> BarPositionHelper::clone() const
 {
-    BarPositionHelper* pRet = new BarPositionHelper(*this);
-    return pRet;
+    return o3tl::make_unique<BarPositionHelper>(*this);
 }
 
 void BarPositionHelper::updateSeriesCount( double fSeriesCount )
diff --git a/chart2/source/view/charttypes/BarPositionHelper.hxx b/chart2/source/view/charttypes/BarPositionHelper.hxx
index 59f22d3bedde..e63fa883708e 100644
--- a/chart2/source/view/charttypes/BarPositionHelper.hxx
+++ b/chart2/source/view/charttypes/BarPositionHelper.hxx
@@ -33,7 +33,7 @@ public:
     BarPositionHelper( const BarPositionHelper& rSource );
     virtual ~BarPositionHelper() override;
 
-    virtual PlottingPositionHelper* clone() const override;
+    virtual std::unique_ptr<PlottingPositionHelper> clone() const override;
 
     void updateSeriesCount( double fSeriesCount ); /*only enter the size of x stacked series*/
 
diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx
index ce592dcc89eb..b2af514f763c 100644
--- a/chart2/source/view/charttypes/VSeriesPlotter.cxx
+++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx
@@ -175,11 +175,6 @@ VSeriesPlotter::~VSeriesPlotter()
     }
     m_aZSlots.clear();
 
-    for (auto const& elem : m_aSecondaryPosHelperMap)
-    {
-        PlottingPositionHelper* pPosHelper = elem.second;
-        delete pPosHelper;
-    }
     m_aSecondaryPosHelperMap.clear();
 
     m_aSecondaryValueScales.clear();
@@ -2077,15 +2072,15 @@ PlottingPositionHelper& VSeriesPlotter::getPlottingPositionHelper( sal_Int32 nAx
         tSecondaryPosHelperMap::const_iterator aPosIt = m_aSecondaryPosHelperMap.find( nAxisIndex );
         if( aPosIt != m_aSecondaryPosHelperMap.end() )
         {
-            pRet = aPosIt->second;
+            pRet = aPosIt->second.get();
         }
         else if (m_pPosHelper)
         {
             tSecondaryValueScales::const_iterator aScaleIt = m_aSecondaryValueScales.find( nAxisIndex );
             if( aScaleIt != m_aSecondaryValueScales.end() )
             {
-                pRet = m_pPosHelper->createSecondaryPosHelper( aScaleIt->second );
-                m_aSecondaryPosHelperMap[nAxisIndex] = pRet;
+                m_aSecondaryPosHelperMap[nAxisIndex] = m_pPosHelper->createSecondaryPosHelper( aScaleIt->second );
+                pRet = m_aSecondaryPosHelperMap[nAxisIndex].get();
             }
         }
     }
diff --git a/chart2/source/view/inc/PlottingPositionHelper.hxx b/chart2/source/view/inc/PlottingPositionHelper.hxx
index b5e54d3cc06d..bf70d7f9c28a 100644
--- a/chart2/source/view/inc/PlottingPositionHelper.hxx
+++ b/chart2/source/view/inc/PlottingPositionHelper.hxx
@@ -46,8 +46,8 @@ public:
     PlottingPositionHelper( const PlottingPositionHelper& rSource );
     virtual ~PlottingPositionHelper();
 
-    virtual PlottingPositionHelper* clone() const;
-    PlottingPositionHelper* createSecondaryPosHelper( const ExplicitScaleData& rSecondaryScale );
+    virtual std::unique_ptr<PlottingPositionHelper> clone() const;
+    std::unique_ptr<PlottingPositionHelper> createSecondaryPosHelper( const ExplicitScaleData& rSecondaryScale );
 
     virtual void setTransformationSceneToScreen( const css::drawing::HomogenMatrix& rMatrix);
 
@@ -143,7 +143,7 @@ public:
     PolarPlottingPositionHelper( const PolarPlottingPositionHelper& rSource );
     virtual ~PolarPlottingPositionHelper() override;
 
-    virtual PlottingPositionHelper* clone() const override;
+    virtual std::unique_ptr<PlottingPositionHelper> clone() const override;
 
     virtual void setTransformationSceneToScreen( const css::drawing::HomogenMatrix& rMatrix) override;
     virtual void setScales( const std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis ) override;
diff --git a/chart2/source/view/inc/VSeriesPlotter.hxx b/chart2/source/view/inc/VSeriesPlotter.hxx
index e1eac757381e..e181c7590a71 100644
--- a/chart2/source/view/inc/VSeriesPlotter.hxx
+++ b/chart2/source/view/inc/VSeriesPlotter.hxx
@@ -424,7 +424,7 @@ private:
     typedef std::map< sal_Int32 , ExplicitScaleData > tSecondaryValueScales;
     tSecondaryValueScales   m_aSecondaryValueScales;
 
-    typedef std::map< sal_Int32 , PlottingPositionHelper* > tSecondaryPosHelperMap;
+    typedef std::map< sal_Int32 , std::unique_ptr<PlottingPositionHelper> > tSecondaryPosHelperMap;
     mutable tSecondaryPosHelperMap   m_aSecondaryPosHelperMap;
     css::awt::Size      m_aPageReferenceSize;
 };
diff --git a/chart2/source/view/main/PlottingPositionHelper.cxx b/chart2/source/view/main/PlottingPositionHelper.cxx
index 0af1fe3d35fc..6c05d96b233a 100644
--- a/chart2/source/view/main/PlottingPositionHelper.cxx
+++ b/chart2/source/view/main/PlottingPositionHelper.cxx
@@ -33,6 +33,7 @@
 #include <com/sun/star/drawing/Position3D.hpp>
 #include <com/sun/star/drawing/XShapes.hpp>
 
+#include <o3tl/make_unique.hxx>
 #include <rtl/math.hxx>
 #include <tools/helpers.hxx>
 
@@ -81,15 +82,14 @@ PlottingPositionHelper::~PlottingPositionHelper()
 
 }
 
-PlottingPositionHelper* PlottingPositionHelper::clone() const
+std::unique_ptr<PlottingPositionHelper> PlottingPositionHelper::clone() const
 {
-    PlottingPositionHelper* pRet = new PlottingPositionHelper(*this);
-    return pRet;
+    return o3tl::make_unique<PlottingPositionHelper>(*this);
 }
 
-PlottingPositionHelper* PlottingPositionHelper::createSecondaryPosHelper( const ExplicitScaleData& rSecondaryScale )
+std::unique_ptr<PlottingPositionHelper> PlottingPositionHelper::createSecondaryPosHelper( const ExplicitScaleData& rSecondaryScale )
 {
-    PlottingPositionHelper* pRet = clone();
+    auto pRet = clone();
     pRet->m_aScales[1]=rSecondaryScale;
     return pRet;
 }
@@ -338,10 +338,9 @@ PolarPlottingPositionHelper::~PolarPlottingPositionHelper()
 {
 }
 
-PlottingPositionHelper* PolarPlottingPositionHelper::clone() const
+std::unique_ptr<PlottingPositionHelper> PolarPlottingPositionHelper::clone() const
 {
-    PolarPlottingPositionHelper* pRet = new PolarPlottingPositionHelper(*this);
-    return pRet;
+    return o3tl::make_unique<PolarPlottingPositionHelper>(*this);
 }
 
 void PolarPlottingPositionHelper::setTransformationSceneToScreen( const drawing::HomogenMatrix& rMatrix)


More information about the Libreoffice-commits mailing list