Skip to content

Commit 556a1c1

Browse files
committed
qspline: Replace alloc_mem, free_mem by C++ new, delete
Remove unneeded assignments and a wrong comment in the destructor. Fix wrong data type for local variable xstarts. Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 52218c3 commit 556a1c1

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

src/ccstruct/quspline.cpp

+19-30
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
**********************************************************************/
1919

2020
#include "allheaders.h"
21-
#include "memry.h"
2221
#include "quadlsq.h"
2322
#include "quspline.h"
2423

@@ -43,8 +42,8 @@ QSPLINE::QSPLINE( //constructor
4342
int32_t index; //segment index
4443

4544
//get memory
46-
xcoords = (int32_t *) alloc_mem ((count + 1) * sizeof (int32_t));
47-
quadratics = (QUAD_COEFFS *) alloc_mem (count * sizeof (QUAD_COEFFS));
45+
xcoords = new int32_t[count + 1];
46+
quadratics = new QUAD_COEFFS[count];
4847
segments = count;
4948
for (index = 0; index < segments; index++) {
5049
//copy them
@@ -77,9 +76,9 @@ int degree //fit required
7776
QLSQ qlsq; /*accumulator */
7877

7978
segments = segcount;
80-
xcoords = (int32_t *) alloc_mem ((segcount + 1) * sizeof (int32_t));
81-
ptcounts = (int32_t *) alloc_mem ((segcount + 1) * sizeof (int32_t));
82-
quadratics = (QUAD_COEFFS *) alloc_mem (segcount * sizeof (QUAD_COEFFS));
79+
xcoords = new int32_t[segcount + 1];
80+
ptcounts = new int32_t[segcount + 1];
81+
quadratics = new QUAD_COEFFS[segcount];
8382
memmove (xcoords, xstarts, (segcount + 1) * sizeof (int32_t));
8483
ptcounts[0] = 0; /*none in any yet */
8584
for (segment = 0, pointindex = 0; pointindex < pointcount; pointindex++) {
@@ -123,7 +122,7 @@ int degree //fit required
123122
quadratics[segment].b = qlsq.get_b ();
124123
quadratics[segment].c = qlsq.get_c ();
125124
}
126-
free_mem(ptcounts);
125+
delete[] ptcounts;
127126
}
128127

129128

@@ -148,16 +147,9 @@ QSPLINE::QSPLINE( //constructor
148147
* Destroy a QSPLINE.
149148
**********************************************************************/
150149

151-
QSPLINE::~QSPLINE ( //constructor
152-
) {
153-
if (xcoords != nullptr) {
154-
free_mem(xcoords);
155-
xcoords = nullptr;
156-
}
157-
if (quadratics != nullptr) {
158-
free_mem(quadratics);
159-
quadratics = nullptr;
160-
}
150+
QSPLINE::~QSPLINE () {
151+
delete[] xcoords;
152+
delete[] quadratics;
161153
}
162154

163155

@@ -169,14 +161,12 @@ QSPLINE::~QSPLINE ( //constructor
169161

170162
QSPLINE & QSPLINE::operator= ( //assignment
171163
const QSPLINE & source) {
172-
if (xcoords != nullptr)
173-
free_mem(xcoords);
174-
if (quadratics != nullptr)
175-
free_mem(quadratics);
164+
delete[] xcoords;
165+
delete[] quadratics;
176166

177167
segments = source.segments;
178-
xcoords = (int32_t *) alloc_mem ((segments + 1) * sizeof (int32_t));
179-
quadratics = (QUAD_COEFFS *) alloc_mem (segments * sizeof (QUAD_COEFFS));
168+
xcoords = new int32_t[segments + 1];
169+
quadratics = new QUAD_COEFFS[segments];
180170
memmove (xcoords, source.xcoords, (segments + 1) * sizeof (int32_t));
181171
memmove (quadratics, source.quadratics, segments * sizeof (QUAD_COEFFS));
182172
return *this;
@@ -303,7 +293,7 @@ void QSPLINE::extrapolate( //linear extrapolation
303293
) {
304294
int segment; /*current segment of spline */
305295
int dest_segment; //dest index
306-
int *xstarts; //new boundaries
296+
int32_t* xstarts; //new boundaries
307297
QUAD_COEFFS *quads; //new ones
308298
int increment; //in size
309299

@@ -312,9 +302,8 @@ void QSPLINE::extrapolate( //linear extrapolation
312302
increment++;
313303
if (increment == 0)
314304
return;
315-
xstarts = (int *) alloc_mem ((segments + 1 + increment) * sizeof (int));
316-
quads =
317-
(QUAD_COEFFS *) alloc_mem ((segments + increment) * sizeof (QUAD_COEFFS));
305+
xstarts = new int32_t[segments + 1 + increment];
306+
quads = new QUAD_COEFFS[segments + increment];
318307
if (xmin < xcoords[0]) {
319308
xstarts[0] = xmin;
320309
quads[0].a = 0;
@@ -339,9 +328,9 @@ void QSPLINE::extrapolate( //linear extrapolation
339328
xstarts[dest_segment] = xmax + 1;
340329
}
341330
segments = dest_segment;
342-
free_mem(xcoords);
343-
free_mem(quadratics);
344-
xcoords = (int32_t *) xstarts;
331+
delete[] xcoords;
332+
delete[] quadratics;
333+
xcoords = xstarts;
345334
quadratics = quads;
346335
}
347336

0 commit comments

Comments
 (0)