Skip to content

Commit 2135376

Browse files
committed
STYLE: Replace pointers initialized by new T[N] with fixed arrays
Changed the type of local variables that were declared as pointer and initialized by `new T[N]`, to the corresponding fixed size C-style array type, `T[N]`. Removed the corresponding `delete []` statements. Cases found by the following regular expressions: new \w+\[\d\] new \w+\[V\w+\] new \w+\[\w*Dimension\] Aims to increase code readability, and may (possibly) improve the run-time performance. Following C++ Core Guidelines, April 10, 2022, "Prefer scoped objects, don’t heap-allocate unnecessarily", https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#r5-prefer-scoped-objects-dont-heap-allocate-unnecessarily
1 parent ccffc5e commit 2135376

File tree

6 files changed

+17
-35
lines changed

6 files changed

+17
-35
lines changed

Modules/Core/SpatialObjects/include/itkMetaDTITubeConverter.hxx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,14 @@ MetaDTITubeConverter<VDimension>::MetaObjectToSpatialObject(const MetaObjectType
9292

9393
pnt.SetPositionInObjectSpace(point);
9494

95-
auto * tensor = new float[6];
95+
float tensor[6];
9696

9797
for (unsigned int ii = 0; ii < 6; ++ii)
9898
{
9999
tensor[ii] = (*it2)->m_TensorMatrix[ii];
100100
}
101101
pnt.SetTensorMatrix(tensor);
102102

103-
delete[] tensor;
104-
105103
// This attribute is optional
106104
if (Math::NotExactlyEquals((*it2)->GetField("r"), -1))
107105
{

Modules/Core/SpatialObjects/include/itkMetaEllipseConverter.hxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ MetaEllipseConverter<VDimension>::SpatialObjectToMetaObject(const SpatialObjectT
7373

7474
auto * ellipseMO = new EllipseMetaObjectType(VDimension);
7575

76-
auto * radii = new float[VDimension];
76+
float radii[VDimension];
7777

7878
for (unsigned int i = 0; i < VDimension; ++i)
7979
{
@@ -92,7 +92,6 @@ MetaEllipseConverter<VDimension>::SpatialObjectToMetaObject(const SpatialObjectT
9292
ellipseSO->GetProperty().GetBlue(),
9393
ellipseSO->GetProperty().GetAlpha());
9494

95-
delete[] radii;
9695
return ellipseMO;
9796
}
9897

Modules/Core/SpatialObjects/include/itkMetaSceneConverter.hxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,12 @@ MetaSceneConverter<VDimension, PixelType, TMeshTraits>::CreateMetaScene(const Sp
258258

259259
metaScene->BinaryData(m_BinaryPoints);
260260

261-
auto * spacing = new float[VDimension];
261+
float spacing[VDimension];
262262
for (unsigned int i = 0; i < VDimension; ++i)
263263
{
264264
spacing[i] = 1;
265265
}
266266
metaScene->ElementSpacing(spacing);
267-
delete[] spacing;
268267

269268
using ListType = typename SpatialObjectType::ChildrenConstListType;
270269

Modules/Filtering/FFT/include/itkFFTWCommon.h

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,10 @@ class Proxy<float>
9898
int threads = 1,
9999
bool canDestroyInput = false)
100100
{
101-
auto * sizes = new int[2];
101+
int sizes[2];
102102
sizes[0] = nx;
103103
sizes[1] = ny;
104104
PlanType plan = Plan_dft_c2r(2, sizes, in, out, flags, threads, canDestroyInput);
105-
delete[] sizes;
106105
return plan;
107106
}
108107

@@ -116,12 +115,11 @@ class Proxy<float>
116115
int threads = 1,
117116
bool canDestroyInput = false)
118117
{
119-
auto * sizes = new int[3];
118+
int sizes[3];
120119
sizes[0] = nx;
121120
sizes[1] = ny;
122121
sizes[2] = nz;
123122
PlanType plan = Plan_dft_c2r(3, sizes, in, out, flags, threads, canDestroyInput);
124-
delete[] sizes;
125123
return plan;
126124
}
127125

@@ -199,11 +197,10 @@ class Proxy<float>
199197
int threads = 1,
200198
bool canDestroyInput = false)
201199
{
202-
auto * sizes = new int[2];
200+
int sizes[2];
203201
sizes[0] = nx;
204202
sizes[1] = ny;
205203
PlanType plan = Plan_dft_r2c(2, sizes, in, out, flags, threads, canDestroyInput);
206-
delete[] sizes;
207204
return plan;
208205
}
209206

@@ -217,12 +214,11 @@ class Proxy<float>
217214
int threads = 1,
218215
bool canDestroyInput = false)
219216
{
220-
auto * sizes = new int[3];
217+
int sizes[3];
221218
sizes[0] = nx;
222219
sizes[1] = ny;
223220
sizes[2] = nz;
224221
PlanType plan = Plan_dft_r2c(3, sizes, in, out, flags, threads, canDestroyInput);
225-
delete[] sizes;
226222
return plan;
227223
}
228224

@@ -302,11 +298,10 @@ class Proxy<float>
302298
int threads = 1,
303299
bool canDestroyInput = false)
304300
{
305-
auto * sizes = new int[2];
301+
int sizes[2];
306302
sizes[0] = nx;
307303
sizes[1] = ny;
308304
PlanType plan = Plan_dft(2, sizes, in, out, sign, flags, threads, canDestroyInput);
309-
delete[] sizes;
310305
return plan;
311306
}
312307

@@ -321,12 +316,11 @@ class Proxy<float>
321316
int threads = 1,
322317
bool canDestroyInput = false)
323318
{
324-
auto * sizes = new int[3];
319+
int sizes[3];
325320
sizes[0] = nx;
326321
sizes[1] = ny;
327322
sizes[2] = nz;
328323
PlanType plan = Plan_dft(3, sizes, in, out, sign, flags, threads, canDestroyInput);
329-
delete[] sizes;
330324
return plan;
331325
}
332326

@@ -440,11 +434,10 @@ class Proxy<double>
440434
int threads = 1,
441435
bool canDestroyInput = false)
442436
{
443-
auto * sizes = new int[2];
437+
int sizes[2];
444438
sizes[0] = nx;
445439
sizes[1] = ny;
446440
PlanType plan = Plan_dft_c2r(2, sizes, in, out, flags, threads, canDestroyInput);
447-
delete[] sizes;
448441
return plan;
449442
}
450443

@@ -458,12 +451,11 @@ class Proxy<double>
458451
int threads = 1,
459452
bool canDestroyInput = false)
460453
{
461-
auto * sizes = new int[3];
454+
int sizes[3];
462455
sizes[0] = nx;
463456
sizes[1] = ny;
464457
sizes[2] = nz;
465458
PlanType plan = Plan_dft_c2r(3, sizes, in, out, flags, threads, canDestroyInput);
466-
delete[] sizes;
467459
return plan;
468460
}
469461

@@ -541,11 +533,10 @@ class Proxy<double>
541533
int threads = 1,
542534
bool canDestroyInput = false)
543535
{
544-
auto * sizes = new int[2];
536+
int sizes[2];
545537
sizes[0] = nx;
546538
sizes[1] = ny;
547539
PlanType plan = Plan_dft_r2c(2, sizes, in, out, flags, threads, canDestroyInput);
548-
delete[] sizes;
549540
return plan;
550541
}
551542

@@ -559,12 +550,11 @@ class Proxy<double>
559550
int threads = 1,
560551
bool canDestroyInput = false)
561552
{
562-
auto * sizes = new int[3];
553+
int sizes[3];
563554
sizes[0] = nx;
564555
sizes[1] = ny;
565556
sizes[2] = nz;
566557
PlanType plan = Plan_dft_r2c(3, sizes, in, out, flags, threads, canDestroyInput);
567-
delete[] sizes;
568558
return plan;
569559
}
570560

@@ -643,11 +633,10 @@ class Proxy<double>
643633
int threads = 1,
644634
bool canDestroyInput = false)
645635
{
646-
auto * sizes = new int[2];
636+
int sizes[2];
647637
sizes[0] = nx;
648638
sizes[1] = ny;
649639
PlanType plan = Plan_dft(2, sizes, in, out, sign, flags, threads, canDestroyInput);
650-
delete[] sizes;
651640
return plan;
652641
}
653642

@@ -662,12 +651,11 @@ class Proxy<double>
662651
int threads = 1,
663652
bool canDestroyInput = false)
664653
{
665-
auto * sizes = new int[3];
654+
int sizes[3];
666655
sizes[0] = nx;
667656
sizes[1] = ny;
668657
sizes[2] = nz;
669658
PlanType plan = Plan_dft(3, sizes, in, out, sign, flags, threads, canDestroyInput);
670-
delete[] sizes;
671659
return plan;
672660
}
673661

Modules/Filtering/ImageFilterBase/include/itkMovingHistogramImageFilter.hxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ MovingHistogramImageFilter<TInputImage, TOutputImage, TKernel, THistogram>::Dyna
107107

108108
// Steps is used to keep track of the order in which the line
109109
// iterator passes over the various dimensions.
110-
auto * Steps = new int[ImageDimension];
110+
int Steps[ImageDimension];
111111

112112
for (i = 0; i < ImageDimension; ++i)
113113
{
@@ -170,7 +170,6 @@ MovingHistogramImageFilter<TInputImage, TOutputImage, TKernel, THistogram>::Dyna
170170
}
171171
progress.Completed(outputRegionForThread.GetSize()[0]);
172172
}
173-
delete[] Steps;
174173
}
175174

176175
template <typename TInputImage, typename TOutputImage, typename TKernel, typename THistogram>

Modules/Filtering/MathematicalMorphology/include/itkMaskedMovingHistogramImageFilter.hxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ MaskedMovingHistogramImageFilter<TInputImage, TMaskImage, TOutputImage, TKernel,
197197

198198
// Steps is used to keep track of the order in which the line
199199
// iterator passes over the various dimensions.
200-
auto * Steps = new int[ImageDimension];
200+
int Steps[ImageDimension];
201201

202202
for (unsigned int i = 0; i < ImageDimension; ++i)
203203
{
@@ -277,7 +277,6 @@ MaskedMovingHistogramImageFilter<TInputImage, TMaskImage, TOutputImage, TKernel,
277277
}
278278
}
279279
}
280-
delete[] Steps;
281280
}
282281

283282
template <typename TInputImage, typename TMaskImage, typename TOutputImage, typename TKernel, typename THistogram>

0 commit comments

Comments
 (0)