Skip to content

Commit e72cf4b

Browse files
committed
STYLE: Call the empty() member function of std containers
Ran Clang-Tidy (LLVM 11.1.0) `readability-container-size-empty`, as motivated at https://clang.llvm.org/extra/clang-tidy/checks/readability-container-size-empty.html : "The emptiness of a container should be checked using the empty() method instead of the size() method. It is not guaranteed that size() is a constant-time function, and it is generally more efficient and also shows clearer intent to use empty(). Furthermore some containers may implement the empty() method but not implement the size() method. Using empty() whenever possible makes it easier to switch to another container in the future." Got extra motivated by having my very first microsoft/STL commit on this topic: microsoft/STL@b95ba0e "Avoid calling size() in empty() member functions" (merged from pull request microsoft/STL#1836) Follows ITK pull request InsightSoftwareConsortium/ITK#414 commit InsightSoftwareConsortium/ITK@c82a5f2 "PERF: readability container size empty", Hans Johnson, January 2019.
1 parent 5d13758 commit e72cf4b

29 files changed

+72
-72
lines changed

Common/OpenCL/Filters/itkGPUBSplineBaseTransform.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ template <typename TScalarType, unsigned int NDimensions>
7171
bool
7272
GPUBSplineBaseTransform<TScalarType, NDimensions>::GetSourceCode(std::string & source) const
7373
{
74-
if (this->m_Sources.size() == 0)
74+
if (this->m_Sources.empty())
7575
{
7676
return false;
7777
}

Common/OpenCL/Filters/itkGPUBSplineInterpolateImageFunction.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ template <typename TInputImage, typename TCoordRep, typename TCoefficientType>
7575
bool
7676
GPUBSplineInterpolateImageFunction<TInputImage, TCoordRep, TCoefficientType>::GetSourceCode(std::string & source) const
7777
{
78-
if (this->m_Sources.size() == 0)
78+
if (this->m_Sources.empty())
7979
{
8080
return false;
8181
}

Common/OpenCL/Filters/itkGPUIdentityTransform.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ template <typename TScalarType, unsigned int NDimensions, typename TParentTransf
3838
bool
3939
GPUIdentityTransform<TScalarType, NDimensions, TParentTransform>::GetSourceCode(std::string & source) const
4040
{
41-
if (this->m_Sources.size() == 0)
41+
if (this->m_Sources.empty())
4242
{
4343
return false;
4444
}

Common/OpenCL/Filters/itkGPULinearInterpolateImageFunction.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ template <typename TInputImage, typename TCoordRep>
4242
bool
4343
GPULinearInterpolateImageFunction<TInputImage, TCoordRep>::GetSourceCode(std::string & source) const
4444
{
45-
if (this->m_Sources.size() == 0)
45+
if (this->m_Sources.empty())
4646
{
4747
return false;
4848
}

Common/OpenCL/Filters/itkGPUMatrixOffsetTransformBase.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ bool
274274
GPUMatrixOffsetTransformBase<TScalarType, NInputDimensions, NOutputDimensions>::GetSourceCode(
275275
std::string & source) const
276276
{
277-
if (this->m_Sources.size() == 0)
277+
if (this->m_Sources.empty())
278278
{
279279
return false;
280280
}

Common/OpenCL/Filters/itkGPUNearestNeighborInterpolateImageFunction.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ template <typename TInputImage, typename TCoordRep>
4242
bool
4343
GPUNearestNeighborInterpolateImageFunction<TInputImage, TCoordRep>::GetSourceCode(std::string & source) const
4444
{
45-
if (this->m_Sources.size() == 0)
45+
if (this->m_Sources.empty())
4646
{
4747
return false;
4848
}

Common/OpenCL/Filters/itkGPUResampleImageFilter.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ bool
10001000
GPUResampleImageFilter<TInputImage, TOutputImage, TInterpolatorPrecisionType>::HasTransform(
10011001
const GPUTransformTypeEnum type) const
10021002
{
1003-
if (this->m_FilterLoopGPUKernelHandle.size() == 0)
1003+
if (this->m_FilterLoopGPUKernelHandle.empty())
10041004
{
10051005
return false;
10061006
}
@@ -1024,7 +1024,7 @@ int
10241024
GPUResampleImageFilter<TInputImage, TOutputImage, TInterpolatorPrecisionType>::GetTransformHandle(
10251025
const GPUTransformTypeEnum type) const
10261026
{
1027-
if (this->m_FilterLoopGPUKernelHandle.size() == 0)
1027+
if (this->m_FilterLoopGPUKernelHandle.empty())
10281028
{
10291029
return -1;
10301030
}

Common/OpenCL/Filters/itkGPUTranslationTransformBase.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ template <typename TScalarType, unsigned int NDimensions>
181181
bool
182182
GPUTranslationTransformBase<TScalarType, NDimensions>::GetSourceCode(std::string & source) const
183183
{
184-
if (this->m_Sources.size() == 0)
184+
if (this->m_Sources.empty())
185185
{
186186
return false;
187187
}

Common/OpenCL/ITKimprovements/itkOpenCLContext.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ OpenCLContext::CreateProgramFromSourceCode(const std::string & sourceCode,
11351135
// kernel code must exist in a text file separate from the code of the host.
11361136
// Also the full path to the file has to be provided.
11371137
const std::string fileName = GetOpenCLDebugFileName(oclSource);
1138-
if (prefixSourceCode != "")
1138+
if (!prefixSourceCode.empty())
11391139
{
11401140
std::ofstream debugfile(fileName.c_str());
11411141
if (debugfile.is_open() == false)
@@ -1215,11 +1215,11 @@ OpenCLContext::CreateProgramFromSourceFile(const std::string & filename,
12151215
// To work with the Intel SDK for OpenCL* - Debugger plug-in, the OpenCL*
12161216
// kernel code must exist in a text file separate from the code of the host.
12171217
// Also the full path to the file has to be provided.
1218-
if (prefixSourceCode != "")
1218+
if (!prefixSourceCode.empty())
12191219
{
12201220
fileName = GetOpenCLDebugFileName(oclSource);
12211221
}
1222-
if (prefixSourceCode != "")
1222+
if (!prefixSourceCode.empty())
12231223
{
12241224
std::ofstream debugfile(fileName.c_str());
12251225
if (debugfile.is_open() == false)

Common/OpenCL/ITKimprovements/itkOpenCLProgram.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ GetOpenCLMathAndOptimizationOptions(std::string & options)
6868

6969
#ifndef OPENCL_OPTIMIZATION_OPT_DISABLE
7070
# ifdef OPENCL_OPTIMIZATION_MAD_ENABLE
71-
if (options.size() != 0)
71+
if (!options.empty())
7272
{
7373
options.append(" ");
7474
}
@@ -262,7 +262,7 @@ OpenCLProgram::Build(const std::list<OpenCLDevice> & devices, const std::string
262262
oclOptions = !extraBuildOptions.empty() ? oclOptions + " " + extraBuildOptions : oclOptions;
263263

264264
#if (defined(_WIN32) && defined(_DEBUG)) || !defined(NDEBUG)
265-
if (GetFileName().size() > 0)
265+
if (!GetFileName().empty())
266266
{
267267
const std::string message = "clBuildProgram from file '" + GetFileName() + "'";
268268
this->GetContext()->OpenCLDebug(message);
@@ -296,7 +296,7 @@ OpenCLProgram::Build(const std::list<OpenCLDevice> & devices, const std::string
296296
error = clBuildProgram(this->m_Id, devs.size(), &devs[0], oclOptions.empty() ? 0 : &oclOptions[0], 0, 0);
297297
}
298298
#else
299-
if (devs.size() == 0)
299+
if (devs.empty())
300300
{
301301
error = clBuildProgram(this->m_Id, 0, 0, oclOptions.empty() ? 0 : &oclOptions[0], 0, 0);
302302
}

0 commit comments

Comments
 (0)