From 994bd46796affd55ce1c4b7223074580df93391a Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Thu, 8 Sep 2022 16:59:38 +0200 Subject: [PATCH] STYLE: Let Operator Fill allocate temp_slice on the stack, without `new` Might speed up the "Fill" member functions of AnnulusOperator, ImageKernelOperator, LaplacianOperator, and NeighborhoodOperator. --- Modules/Core/Common/include/itkAnnulusOperator.hxx | 5 ++--- Modules/Core/Common/include/itkImageKernelOperator.hxx | 6 ++---- Modules/Core/Common/include/itkLaplacianOperator.hxx | 6 ++---- .../Core/Common/include/itkNeighborhoodOperator.hxx | 10 +++++----- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/Modules/Core/Common/include/itkAnnulusOperator.hxx b/Modules/Core/Common/include/itkAnnulusOperator.hxx index 4b9aa0d1c1c..abe3ff0fd88 100644 --- a/Modules/Core/Common/include/itkAnnulusOperator.hxx +++ b/Modules/Core/Common/include/itkAnnulusOperator.hxx @@ -43,10 +43,9 @@ template void AnnulusOperator::Fill(const CoefficientVector & coeff) { - auto * temp_slice = new std::slice(0, coeff.size(), 1); + const std::slice temp_slice(0, coeff.size(), 1); - typename Self::SliceIteratorType data(this, *temp_slice); - delete temp_slice; + typename Self::SliceIteratorType data(this, temp_slice); auto it = coeff.begin(); diff --git a/Modules/Core/Common/include/itkImageKernelOperator.hxx b/Modules/Core/Common/include/itkImageKernelOperator.hxx index b8e63dd1dfe..e4870010d52 100644 --- a/Modules/Core/Common/include/itkImageKernelOperator.hxx +++ b/Modules/Core/Common/include/itkImageKernelOperator.hxx @@ -87,14 +87,12 @@ ImageKernelOperator::Fill(const CoefficientVecto // Initialize all coefficients to zero this->InitializeToZero(); - std::slice * temp_slice; typename CoefficientVector::const_iterator it; - temp_slice = new std::slice(0, coeff.size(), 1); + const std::slice temp_slice(0, coeff.size(), 1); it = coeff.begin(); - typename Superclass::SliceIteratorType data(this, *temp_slice); - delete temp_slice; + typename Superclass::SliceIteratorType data(this, temp_slice); // Copy the coefficients into the neighborhood, truncating them if there // are too many. diff --git a/Modules/Core/Common/include/itkLaplacianOperator.hxx b/Modules/Core/Common/include/itkLaplacianOperator.hxx index 41ad7f66803..3cf38eb150b 100644 --- a/Modules/Core/Common/include/itkLaplacianOperator.hxx +++ b/Modules/Core/Common/include/itkLaplacianOperator.hxx @@ -49,11 +49,9 @@ LaplacianOperator::Fill(const CoefficientVector { typename Superclass::CoefficientVector::const_iterator it; - std::slice * temp_slice; - temp_slice = new std::slice(0, coeff.size(), 1); + const std::slice temp_slice(0, coeff.size(), 1); - typename Self::SliceIteratorType data(this, *temp_slice); - delete temp_slice; + typename Self::SliceIteratorType data(this, temp_slice); it = coeff.begin(); diff --git a/Modules/Core/Common/include/itkNeighborhoodOperator.hxx b/Modules/Core/Common/include/itkNeighborhoodOperator.hxx index ce71d992e75..007c50eb6d1 100644 --- a/Modules/Core/Common/include/itkNeighborhoodOperator.hxx +++ b/Modules/Core/Common/include/itkNeighborhoodOperator.hxx @@ -122,21 +122,21 @@ NeighborhoodOperator::FillCenteredDirectional(co const int sizediff = (static_cast(size) - static_cast(coeff.size())) >> 1; // Create a slice iterator centered in the neighborhood. - std::slice * temp_slice; + std::slice temp_slice; typename CoefficientVector::const_iterator it; if (sizediff >= 0) { - temp_slice = new std::slice(start + sizediff * stride, coeff.size(), stride); + temp_slice = std::slice(start + sizediff * stride, coeff.size(), stride); it = coeff.begin(); } else { - temp_slice = new std::slice(start, size, stride); + temp_slice = std::slice(start, size, stride); it = coeff.begin() - sizediff; } - SliceIteratorType data(this, *temp_slice); - delete temp_slice; + + SliceIteratorType data(this, temp_slice); // Copy the coefficients into the neighborhood, truncating them if there // are too many.