Skip to content

Commit e9af5c5

Browse files
hjmjohnsondzenanz
authored andcommitted
STYLE: Reduce indentation else after return
Reduce indentation where possible and where it makes understanding code easier. Early exit is one of the suggested enforcements of that. Please do not use else or else if after something that interrupts control flow - like return, break, continue, throw. clang-tidy readability-else-after-return
1 parent bc26163 commit e9af5c5

File tree

395 files changed

+2671
-3783
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

395 files changed

+2671
-3783
lines changed

Examples/RegistrationITKv4/ImageRegistrationHistogramPlotter.cxx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ class RescaleDynamicRangeFunctor
147147
{
148148
return static_cast<OutputPixelType>(255);
149149
}
150-
else
151-
{
152-
return itk::Math::Round<OutputPixelType>(-(30.0 * std::log(A)));
153-
}
150+
return itk::Math::Round<OutputPixelType>(-(30.0 * std::log(A)));
154151
}
155152
else
156153
{

Examples/Statistics/WeightedSampleStatistics.cxx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,8 @@ class ExampleWeightFunction
8484
{
8585
return 0.5;
8686
}
87-
else
88-
{
89-
return 0.01;
90-
}
87+
88+
return 0.01;
9189
}
9290

9391
protected:

Modules/Bridge/VTK/src/itkVTKImageExportBase.cxx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,8 @@ VTKImageExportBase::PipelineModifiedCallback()
159159
m_LastPipelineMTime = pipelineMTime;
160160
return 1;
161161
}
162-
else
163-
{
164-
return 0;
165-
}
162+
163+
return 0;
166164
}
167165

168166
/**

Modules/Core/Common/include/itkBSplineDerivativeKernelFunction.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class ITK_TEMPLATE_EXPORT BSplineDerivativeKernelFunction : public KernelFunctio
109109
{
110110
return TRealValueType{ 0.5 };
111111
}
112-
else if ((u > TRealValueType{ -1.0 }) && (u < TRealValueType{ 0.0 }))
112+
if ((u > TRealValueType{ -1.0 }) && (u < TRealValueType{ 0.0 }))
113113
{
114114
return TRealValueType{ 1.0 };
115115
}
@@ -139,7 +139,7 @@ class ITK_TEMPLATE_EXPORT BSplineDerivativeKernelFunction : public KernelFunctio
139139
{
140140
return (TRealValueType{ -2.0 } * u);
141141
}
142-
else if ((u >= TRealValueType{ 0.5 }) && (u < TRealValueType{ 1.5 }))
142+
if ((u >= TRealValueType{ 0.5 }) && (u < TRealValueType{ 1.5 }))
143143
{
144144
return (TRealValueType{ -1.5 } + u);
145145
}
@@ -161,7 +161,7 @@ class ITK_TEMPLATE_EXPORT BSplineDerivativeKernelFunction : public KernelFunctio
161161
{
162162
return (TRealValueType{ -2.0 } * u + TRealValueType{ 1.5 } * u * u);
163163
}
164-
else if ((u > TRealValueType{ -1.0 }) && (u < TRealValueType{ 0.0 }))
164+
if ((u > TRealValueType{ -1.0 }) && (u < TRealValueType{ 0.0 }))
165165
{
166166
return (TRealValueType{ -2.0 } * u - TRealValueType{ 1.5 } * u * u);
167167
}

Modules/Core/Common/include/itkBSplineKernelFunction.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
103103
{
104104
return TRealValueType{ 1.0 };
105105
}
106-
else if (Math::ExactlyEquals(absValue, TRealValueType{ 0.5 }))
106+
if (Math::ExactlyEquals(absValue, TRealValueType{ 0.5 }))
107107
{
108108
return TRealValueType{ 0.5 };
109109
}
@@ -122,10 +122,8 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
122122
{
123123
return TRealValueType{ 1.0 } - absValue;
124124
}
125-
else
126-
{
127-
return TRealValueType{ 0.0 };
128-
}
125+
126+
return TRealValueType{ 0.0 };
129127
}
130128

131129
/** Second order spline. */
@@ -138,7 +136,7 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
138136
const TRealValueType sqrValue = itk::Math::sqr(absValue);
139137
return TRealValueType{ 0.75 } - sqrValue;
140138
}
141-
else if (absValue < TRealValueType{ 1.5 })
139+
if (absValue < TRealValueType{ 1.5 })
142140
{
143141
const TRealValueType sqrValue = itk::Math::sqr(absValue);
144142
// NOTE: 1.0/8.0 == 0.125
@@ -162,7 +160,7 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
162160
return (TRealValueType{ 4.0 } - TRealValueType{ 6.0 } * sqrValue + TRealValueType{ 3.0 } * sqrValue * absValue) /
163161
TRealValueType{ 6.0 };
164162
}
165-
else if (absValue < TRealValueType{ 2.0 })
163+
if (absValue < TRealValueType{ 2.0 })
166164
{
167165
const TRealValueType sqrValue = itk::Math::sqr(absValue);
168166
return (TRealValueType{ 8.0 } - TRealValueType{ 12.0 } * absValue + TRealValueType{ 6.0 } * sqrValue -

Modules/Core/Common/include/itkColorTable.hxx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,10 @@ ColorTable<TComponent>::GetColor(unsigned int c)
281281
{
282282
return m_Color[c];
283283
}
284-
else
285-
{
286-
RGBPixel<TComponent> pixel;
287-
pixel.Set(0, 0, 0);
288-
return pixel;
289-
}
284+
285+
RGBPixel<TComponent> pixel;
286+
pixel.Set(0, 0, 0);
287+
return pixel;
290288
}
291289

292290
template <typename TComponent>
@@ -329,10 +327,8 @@ ColorTable<TComponent>::GetColorName(unsigned int c)
329327
{
330328
return m_ColorName[c];
331329
}
332-
else
333-
{
334-
return "";
335-
}
330+
331+
return "";
336332
}
337333

338334
template <typename TComponent>

Modules/Core/Common/include/itkConstNeighborhoodIterator.hxx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ConstNeighborhoodIterator<TImage, TBoundaryCondition>::IndexInBounds(const Neigh
5555
{
5656
return true;
5757
}
58-
else if (this->InBounds()) // Is this whole neighborhood in bounds?
58+
if (this->InBounds()) // Is this whole neighborhood in bounds?
5959
{
6060
return true;
6161
}
@@ -108,7 +108,7 @@ ConstNeighborhoodIterator<TImage, TBoundaryCondition>::IndexInBounds(const Neigh
108108
{
109109
return true;
110110
}
111-
else if (this->InBounds()) // Is this whole neighborhood in bounds?
111+
if (this->InBounds()) // Is this whole neighborhood in bounds?
112112
{
113113
return true;
114114
}
@@ -162,21 +162,19 @@ ConstNeighborhoodIterator<TImage, TBoundaryCondition>::GetPixel(NeighborIndexTyp
162162
IsInBounds = true;
163163
return (m_NeighborhoodAccessorFunctor.Get(this->operator[](n)));
164164
}
165+
166+
OffsetType offset;
167+
OffsetType internalIndex;
168+
const bool flag = this->IndexInBounds(n, internalIndex, offset);
169+
if (flag)
170+
{
171+
IsInBounds = true;
172+
return (m_NeighborhoodAccessorFunctor.Get(this->operator[](n)));
173+
}
165174
else
166175
{
167-
OffsetType offset;
168-
OffsetType internalIndex;
169-
const bool flag = this->IndexInBounds(n, internalIndex, offset);
170-
if (flag)
171-
{
172-
IsInBounds = true;
173-
return (m_NeighborhoodAccessorFunctor.Get(this->operator[](n)));
174-
}
175-
else
176-
{
177-
IsInBounds = false;
178-
return (m_NeighborhoodAccessorFunctor.BoundaryCondition(internalIndex, offset, this, this->m_BoundaryCondition));
179-
}
176+
IsInBounds = false;
177+
return (m_NeighborhoodAccessorFunctor.BoundaryCondition(internalIndex, offset, this, this->m_BoundaryCondition));
180178
}
181179
}
182180

Modules/Core/Common/include/itkConstNeighborhoodIteratorWithOnlyIndex.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ ConstNeighborhoodIteratorWithOnlyIndex<TImage>::IndexInBounds(const NeighborInde
5757
{
5858
return true;
5959
}
60-
else if (this->InBounds()) // Is this whole neighborhood in bounds?
60+
if (this->InBounds()) // Is this whole neighborhood in bounds?
6161
{
6262
return true;
6363
}

Modules/Core/Common/include/itkConstShapedNeighborhoodIterator.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,8 @@ class ITK_TEMPLATE_EXPORT ConstShapedNeighborhoodIterator : private Neighborhood
179179
{
180180
return true;
181181
}
182-
else
183-
{
184-
return false;
185-
}
182+
183+
return false;
186184
}
187185

188186
void

Modules/Core/Common/include/itkConstShapedNeighborhoodIterator.hxx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,17 @@ ConstShapedNeighborhoodIterator<TImage, TBoundaryCondition>::DeactivateIndex(Nei
9292
{
9393
return;
9494
}
95-
else
95+
96+
while (n != *it)
9697
{
97-
while (n != *it)
98+
++it;
99+
if (it == m_ActiveIndexList.end())
98100
{
99-
++it;
100-
if (it == m_ActiveIndexList.end())
101-
{
102-
return;
103-
}
101+
return;
104102
}
105-
m_ActiveIndexList.erase(it);
106103
}
104+
m_ActiveIndexList.erase(it);
105+
107106

108107
// Did we just deactivate the index at the center of the neighborhood?
109108
if (n == this->GetCenterNeighborhoodIndex())

0 commit comments

Comments
 (0)