Kaydet (Commit) 13ec3a1d authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in mgcLinearSystemD

Change-Id: I2043b6473ef18828a903a8da9faa98e3fd4dba0a
Reviewed-on: https://gerrit.libreoffice.org/59025
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 65360836
......@@ -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: */
......@@ -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];
......
......@@ -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]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment