Skip to content

Commit

Permalink
STYLE: Replace postfix by prefix increment in for loops in ITK/Modules
Browse files Browse the repository at this point in the history
Applied to ITK/Modules, at the GNU bash prompt:

    find . \( -iname *.cxx -or -iname *.hxx -or -iname *.h \) -exec perl -pi -w -e 's/(\s+for \(.*; .+); (\w+)\+\+\)/$1; ++$2)/g;' {} \;

(Excluded ITK/Modules/ThirdParty.)

According to Herb Sutter, Andrei Alexandrescu - C++ Coding Standards:
101 Rules, Guidelines, and Best Practices: "Prefer the canonical form of
++ and --. Prefer calling the prefix forms"

Follow-up to:
pull request InsightSoftwareConsortium#2493
commit f81578b
"STYLE: Replace postfix by prefix increment in `for` loops in Core/Common"
  • Loading branch information
N-Dekker committed Apr 23, 2021
1 parent f7504ec commit 971aef2
Show file tree
Hide file tree
Showing 1,162 changed files with 5,732 additions and 5,732 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ LevelOrderTreeIterator<TTreeType>::FindNextNodeHelp() const

int size = currentNode->CountChildren();

for (int i = 0; i < size; i++)
for (int i = 0; i < size; ++i)
{
auto * child = dynamic_cast<TreeNodeType *>(currentNode->GetChild(i));
if (child != nullptr)
Expand Down
8 changes: 4 additions & 4 deletions Modules/Compatibility/Deprecated/include/itkTreeNode.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ TreeNode<TValue>::ReplaceChild(Self * oldChild, Self * newChild)
{
const auto numberOfChildren = static_cast<ChildIdentifier>(m_Children.size());

for (ChildIdentifier i = 0; i < numberOfChildren; i++)
for (ChildIdentifier i = 0; i < numberOfChildren; ++i)
{
if (m_Children[i] == oldChild)
{
Expand All @@ -171,7 +171,7 @@ TreeNode<TValue>::ChildPosition(const Self * node) const
{
const auto numberOfChildren = static_cast<ChildIdentifier>(m_Children.size());

for (ChildIdentifier i = 0; i < numberOfChildren; i++)
for (ChildIdentifier i = 0; i < numberOfChildren; ++i)
{
if (m_Children[i] == node)
{
Expand All @@ -188,7 +188,7 @@ TreeNode<TValue>::ChildPosition(TValue element) const
{
const auto numberOfChildren = static_cast<ChildIdentifier>(m_Children.size());

for (ChildIdentifier i = 0; i < numberOfChildren; i++)
for (ChildIdentifier i = 0; i < numberOfChildren; ++i)
{
if (m_Children[i]->Get() == element)
{
Expand Down Expand Up @@ -220,7 +220,7 @@ TreeNode<TValue>::AddChild(ChildIdentifier number, Self * node)
if (childId > numberOfChildren)
{
m_Children.resize(childId);
for (ChildIdentifier i = numberOfChildren; i <= childId; i++)
for (ChildIdentifier i = numberOfChildren; i <= childId; ++i)
{
m_Children[i] = nullptr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class VectorCast
using OutputValueType = typename TOutput::ValueType;

TOutput value;
for (unsigned int k = 0; k < TOutput::Dimension; k++)
for (unsigned int k = 0; k < TOutput::Dimension; ++k)
{
value[k] = static_cast<OutputValueType>(A[k]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ VectorCentralDifferenceImageFunction<TInputImage, TCoordRep>::EvaluateAtIndex(co
const typename InputImageType::SizeType & size = this->GetInputImage()->GetBufferedRegion().GetSize();
const typename InputImageType::IndexType & start = this->GetInputImage()->GetBufferedRegion().GetIndex();

for (unsigned int dim = 0; dim < TInputImage::ImageDimension; dim++)
for (unsigned int dim = 0; dim < TInputImage::ImageDimension; ++dim)
{
// bounds checking
if (index[dim] < start[dim] + 1 || index[dim] > (start[dim] + static_cast<OffsetValueType>(size[dim]) - 2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ VectorResampleImageFilter<TInputImage, TOutputImage, TInterpolatorPrecisionType>
NumericTraits<PixelType>::SetLength(pixval, numberOfComponents);

const OutputType value = m_Interpolator->EvaluateAtContinuousIndex(inputIndex);
for (unsigned int i = 0; i < numberOfComponents; i++)
for (unsigned int i = 0; i < numberOfComponents; ++i)
{
pixval[i] = static_cast<PixelComponentType>(value[i]);
}
Expand Down
16 changes: 8 additions & 8 deletions Modules/Compatibility/Deprecated/test/itkAtomicIntTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ itk::Object::Pointer AnObject;
ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
MyFunction(void *)
{
for (unsigned i = 0; i < Target / NumThreads; i++)
for (unsigned i = 0; i < Target / NumThreads; ++i)
{
Total++;
int idx = ++TotalAtomic;
Expand All @@ -75,7 +75,7 @@ MyFunction(void *)
ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
MyFunction2(void *)
{
for (unsigned i = 0; i < Target / NumThreads; i++)
for (unsigned i = 0; i < Target / NumThreads; ++i)
{
--TotalAtomic;

Expand All @@ -88,7 +88,7 @@ MyFunction2(void *)
ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
MyFunction3(void *)
{
for (unsigned i = 0; i < Target / NumThreads; i++)
for (unsigned i = 0; i < Target / NumThreads; ++i)
{
int idx = TotalAtomic += 1;
Values32[idx]++;
Expand All @@ -103,7 +103,7 @@ MyFunction3(void *)
ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
MyFunction4(void *)
{
for (unsigned i = 0; i < Target / NumThreads; i++)
for (unsigned i = 0; i < Target / NumThreads; ++i)
{
TotalAtomic++;
TotalAtomic += 1;
Expand All @@ -122,7 +122,7 @@ MyFunction4(void *)
ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
MyFunctionPtr(void *)
{
for (unsigned i = 0; i < Target / NumThreads; i++)
for (unsigned i = 0; i < Target / NumThreads; ++i)
{
itk::int32_t * ptr32 = ++AtomicPtr;
(*ptr32) = 1;
Expand Down Expand Up @@ -223,7 +223,7 @@ itkAtomicIntTest(int, char *[])
Total64 = 0;
TotalAtomic64 = 0;

for (unsigned i = 0; i < Target; i++)
for (unsigned i = 0; i < Target; ++i)
{
Values32[i] = 0;
Values64[i] = 0;
Expand Down Expand Up @@ -259,7 +259,7 @@ itkAtomicIntTest(int, char *[])
std::cout << "Expecting Values64[0] to be 0. Got " << Values64[0] << std::endl;
return 1;
}
for (unsigned i = 1; i < Target; i++)
for (unsigned i = 1; i < Target; ++i)
{
if (Values32[i] != 2)
{
Expand Down Expand Up @@ -297,7 +297,7 @@ itkAtomicIntTest(int, char *[])
std::cout << "Expecting Values64[0] to be 0. Got " << Values64[0] << std::endl;
return 1;
}
for (unsigned i = 1; i < Target; i++)
for (unsigned i = 1; i < Target; ++i)
{
if (Values32[i] != 1)
{
Expand Down
12 changes: 6 additions & 6 deletions Modules/Compatibility/Deprecated/test/itkBarrierTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BarrierTestUserData
{
m_TestFailure = false;
m_NumberOfWorkUnits = number_of_threads;
for (unsigned int i = 0; i < number_of_threads - 1; i++)
for (unsigned int i = 0; i < number_of_threads - 1; ++i)
{
m_Counter[i] = 0;
}
Expand All @@ -54,7 +54,7 @@ BarrierTestIncrement(void * ptr)
itk::ThreadIdType threadId = ((itk::MultiThreaderBase::WorkUnitInfo *)(ptr))->WorkUnitID;
auto * data = static_cast<BarrierTestUserData *>(((itk::MultiThreaderBase::WorkUnitInfo *)(ptr))->UserData);

for (unsigned int i = 0; i < data->m_NumberOfIterations; i++)
for (unsigned int i = 0; i < data->m_NumberOfIterations; ++i)
{
// set the value for this iteration
data->m_Counter[threadId] = i;
Expand All @@ -72,13 +72,13 @@ BarrierCheckIncrement(void * ptr)
{
auto * data = static_cast<BarrierTestUserData *>(((itk::MultiThreaderBase::WorkUnitInfo *)(ptr))->UserData);

for (unsigned int i = 0; i < data->m_NumberOfIterations; i++)
for (unsigned int i = 0; i < data->m_NumberOfIterations; ++i)
{
// Wait for other threads to populate the m_Counter array
data->m_FirstBarrier->Wait();

// Check the values in the m_Counter array
for (unsigned int j = 0; j < data->m_NumberOfWorkUnits - 1; j++)
for (unsigned int j = 0; j < data->m_NumberOfWorkUnits - 1; ++j)
{
if (data->m_Counter[j] != i)
{
Expand Down Expand Up @@ -114,7 +114,7 @@ BarrierSpecialTest(void * ptr)
{
auto * data = static_cast<BarrierTestUserData *>(((itk::MultiThreaderBase::WorkUnitInfo *)(ptr))->UserData);

for (unsigned int j = 0; j < 1000; j++)
for (unsigned int j = 0; j < 1000; ++j)
{
data->m_FirstBarrier->Wait();
}
Expand Down Expand Up @@ -150,7 +150,7 @@ itkBarrierTest(int argc, char * argv[])
multithreader->SetNumberOfWorkUnits(number_of_threads);
multithreader->SetSingleMethod(BarrierTestCallback, &data);

for (unsigned int i = 0; i < 5; i++) // repeat test 5 times
for (unsigned int i = 0; i < 5; ++i) // repeat test 5 times
{
multithreader->SingleMethodExecute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ConditionVariableTestIncCount(void * ptr)

double v = 400.0;

for (unsigned i = 0; i < 10; i++)
for (unsigned i = 0; i < 10; ++i)
{
data->m_Mutex.Lock();
data->m_Counter++;
Expand All @@ -61,7 +61,7 @@ ConditionVariableTestIncCount(void * ptr)
data->m_Mutex.Unlock();

// Do some work here.
for (unsigned j = 0; j < 1000; j++)
for (unsigned j = 0; j < 1000; ++j)
{
v = v / 2.4;
v = v * 2.4;
Expand Down Expand Up @@ -114,7 +114,7 @@ itkConditionVariableTest(int, char *[])
multithreader->SetNumberOfWorkUnits(3);
multithreader->SetSingleMethod(ConditionVariableTestCallback, &cond);

for (unsigned int i = 0; i < 1000; i++)
for (unsigned int i = 0; i < 1000; ++i)
{
cond.m_Counter = 0;
multithreader->SingleMethodExecute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ FiniteDifferenceFunction<TImageType>::FiniteDifferenceFunction()
{
// initialize variables
m_Radius.Fill(0);
for (unsigned int i = 0; i < ImageDimension; i++)
for (unsigned int i = 0; i < ImageDimension; ++i)
{
m_ScaleCoefficients[i] = 1.0;
}
Expand All @@ -51,7 +51,7 @@ template <typename TImageType>
void
FiniteDifferenceFunction<TImageType>::SetScaleCoefficients(const PixelRealType vals[ImageDimension])
{
for (unsigned int i = 0; i < ImageDimension; i++)
for (unsigned int i = 0; i < ImageDimension; ++i)
{
m_ScaleCoefficients[i] = vals[i];
}
Expand All @@ -61,7 +61,7 @@ template <typename TImageType>
void
FiniteDifferenceFunction<TImageType>::GetScaleCoefficients(PixelRealType vals[ImageDimension]) const
{
for (unsigned int i = 0; i < ImageDimension; i++)
for (unsigned int i = 0; i < ImageDimension; ++i)
{
vals[i] = m_ScaleCoefficients[i];
}
Expand All @@ -83,7 +83,7 @@ FiniteDifferenceFunction<TImageType>::ComputeNeighborhoodScales() const
NeighborhoodScalesType neighborhoodScales;

neighborhoodScales.Fill(0.0);
for (unsigned int i = 0; i < ImageDimension; i++)
for (unsigned int i = 0; i < ImageDimension; ++i)
{
if (this->m_Radius[i] > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,14 @@ FiniteDifferenceImageFilter<TInputImage, TOutputImage>::InitializeFunctionCoeffi
using SpacingType = typename TOutputImage::SpacingType;
const SpacingType & spacing = outputImage->GetSpacing();

for (unsigned int i = 0; i < ImageDimension; i++)
for (unsigned int i = 0; i < ImageDimension; ++i)
{
coeffs[i] = 1.0 / static_cast<double>(spacing[i]);
}
}
else
{
for (unsigned int i = 0; i < ImageDimension; i++)
for (unsigned int i = 0; i < ImageDimension; ++i)
{
coeffs[i] = 1.0;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/GPUCommon/include/itkGPUImageDataManager.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ GPUImageDataManager<ImageType>::SetImagePointer(ImageType * img)
IndexType index = region.GetIndex();
SizeType size = region.GetSize();

for (unsigned int d = 0; d < ImageDimension; d++)
for (unsigned int d = 0; d < ImageDimension; ++d)
{
m_BufferedRegionIndex[d] = index[d];
m_BufferedRegionSize[d] = size[d];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ GPUInPlaceImageFilter<TInputImage, TOutputImage, TParentImageFilter>::AllocateOu
typename ImageBaseType::Pointer outputPtr;

// If there are more than one outputs, allocate the remaining outputs
for (unsigned int i = 1; i < this->GetNumberOfOutputs(); i++)
for (unsigned int i = 1; i < this->GetNumberOfOutputs(); ++i)
{
// Check whether the output is an image of the appropriate
// dimension (use ProcessObject's version of the GetInput()
Expand Down
6 changes: 3 additions & 3 deletions Modules/Core/GPUCommon/include/itkGPUReduction.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ GPUReduction<TElement>::RandomTest()
unsigned int bytes = size * sizeof(TElement);
auto * h_idata = (TElement *)malloc(bytes);

for (int i = 0; i < size; i++)
for (int i = 0; i < size; ++i)
{
// Keep the numbers small so we don't get truncation error in the sum
h_idata[i] = (TElement)(rand() & 0xFF);
Expand Down Expand Up @@ -340,7 +340,7 @@ GPUReduction<TElement>::GPUReduce(cl_int n,
std::cout << "CPU_VERIFY sum = " << CPUSum << std::endl;
#endif

for (int i = 0; i < numBlocks; i++)
for (int i = 0; i < numBlocks; ++i)
{
gpu_result += h_odata[i];
}
Expand All @@ -357,7 +357,7 @@ GPUReduction<TElement>::CPUGenerateData(TElement * data, int size)
{
TElement sum = data[0];
// TElement c = (TElement)0.0;
for (int i = 1; i < size; i++)
for (int i = 1; i < size; ++i)
{
// TODO consider using compensated sum algorithm

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ GPUUnaryFunctorImageFilter<TInputImage, TOutputImage, TFunction, TParentImageFil

int ImageDim = (int)TInputImage::ImageDimension;

for (int i = 0; i < ImageDim; i++)
for (int i = 0; i < ImageDim; ++i)
{
imgSize[i] = outSize[i];
}

size_t localSize[3], globalSize[3];
localSize[0] = localSize[1] = localSize[2] = OpenCLGetLocalBlockSize(ImageDim);
for (int i = 0; i < ImageDim; i++)
for (int i = 0; i < ImageDim; ++i)
{
globalSize[i] = localSize[i] * (unsigned int)ceil((float)outSize[i] / (float)localSize[i]); // total # of threads
}
Expand All @@ -68,7 +68,7 @@ GPUUnaryFunctorImageFilter<TInputImage, TOutputImage, TFunction, TParentImageFil
m_UnaryFunctorImageFilterGPUKernelHandle, argidx++, inPtr->GetGPUDataManager());
this->m_GPUKernelManager->SetKernelArgWithImage(
m_UnaryFunctorImageFilterGPUKernelHandle, argidx++, otPtr->GetGPUDataManager());
for (int i = 0; i < (int)TInputImage::ImageDimension; i++)
for (int i = 0; i < (int)TInputImage::ImageDimension; ++i)
{
this->m_GPUKernelManager->SetKernelArg(
m_UnaryFunctorImageFilterGPUKernelHandle, argidx++, sizeof(int), &(imgSize[i]));
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/GPUCommon/src/itkGPUContextManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ GPUContextManager::GPUContextManager()

// create command queues
m_CommandQueue = (cl_command_queue *)malloc(m_NumberOfDevices * sizeof(cl_command_queue));
for (unsigned int i = 0; i < m_NumberOfDevices; i++)
for (unsigned int i = 0; i < m_NumberOfDevices; ++i)
{
m_CommandQueue[i] = clCreateCommandQueue(m_Context, m_Devices[i], 0, &errid);

Expand All @@ -82,7 +82,7 @@ GPUContextManager::GPUContextManager()
GPUContextManager::~GPUContextManager()
{
cl_int errid;
for (unsigned int i = 0; i < m_NumberOfDevices; i++)
for (unsigned int i = 0; i < m_NumberOfDevices; ++i)
{
errid = clReleaseCommandQueue(m_CommandQueue[i]);
OpenCLCheckError(errid, __FILE__, __LINE__, ITK_LOCATION);
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/GPUCommon/src/itkGPUKernelManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ GPUKernelManager::CheckArgumentReady(int kernelIdx)
{
int nArg = m_KernelArgumentReady[kernelIdx].size();

for (int i = 0; i < nArg; i++)
for (int i = 0; i < nArg; ++i)
{
if (!(m_KernelArgumentReady[kernelIdx][i].m_IsReady))
return false;
Expand All @@ -443,7 +443,7 @@ GPUKernelManager::ResetArguments(int kernelIdx)
{
int nArg = m_KernelArgumentReady[kernelIdx].size();

for (int i = 0; i < nArg; i++)
for (int i = 0; i < nArg; ++i)
{
m_KernelArgumentReady[kernelIdx][i].m_IsReady = false;
m_KernelArgumentReady[kernelIdx][i].m_GPUDataManager = (GPUDataManager::Pointer) nullptr;
Expand Down
Loading

0 comments on commit 971aef2

Please sign in to comment.