Commit 797d0979 authored by Sean McBride's avatar Sean McBride

Converted some size() to empty(), for performance and readability

Found & auto-fixed by clang-tidy’s readability-container-size-empty check.

empty() is guaranteed O(1) while size() is not, thus could be faster in some cases.
parent 64cc218f
......@@ -69,7 +69,7 @@ bool vtkCategoryLegend::Paint(vtkContext2D* painter)
// Draw the title (if any)
vtkVector2f stringBounds[2];
float titleHeight = 0.0;
if (this->Title != "")
if (!this->Title.empty())
{
painter->ApplyTextProp(this->TitleProperties.GetPointer());
painter->ComputeStringBounds(this->Title, stringBounds->GetData());
......@@ -100,7 +100,7 @@ bool vtkCategoryLegend::Paint(vtkContext2D* painter)
for (vtkIdType l = 0; l < this->Values->GetNumberOfTuples(); ++l)
{
vtkStdString currentString = this->Values->GetValue(l).ToString();
if (currentString == "")
if (currentString.empty())
{
continue;
}
......@@ -180,7 +180,7 @@ vtkRectf vtkCategoryLegend::GetBoundingRect(vtkContext2D *painter)
// Calculate size of title (if any)
float titleHeight = 0.0f;
float titleWidth = 0.0f;
if (this->Title != "")
if (!this->Title.empty())
{
painter->ApplyTextProp(this->TitleProperties.GetPointer());
......@@ -199,7 +199,7 @@ vtkRectf vtkCategoryLegend::GetBoundingRect(vtkContext2D *painter)
for (vtkIdType l = 0; l < this->Values->GetNumberOfTuples(); ++l)
{
if (this->Values->GetValue(l).ToString() == "")
if (this->Values->GetValue(l).ToString().empty())
{
++numSkippedValues;
continue;
......
......@@ -115,7 +115,7 @@ bool vtkChartLegend::Paint(vtkContext2D *painter)
// This is where everything should be drawn, or dispatched to other methods.
vtkDebugMacro(<< "Paint event called in vtkChartLegend.");
if (!this->Visible || this->Storage->ActivePlots.size() == 0)
if (!this->Visible || this->Storage->ActivePlots.empty())
{
return true;
}
......
......@@ -208,7 +208,7 @@ void vtkChartMatrix::SetSpecificResize(const vtkVector2i& index, const vtkVector
void vtkChartMatrix::ClearSpecificResizes()
{
if (this->SpecificResize.size() != 0)
if (!this->SpecificResize.empty())
{
this->SpecificResize.clear();
this->LayoutIsDirty = true;
......
......@@ -394,7 +394,7 @@ void vtkChartParallelCoordinates::CalculatePlotTransform()
// In the case of parallel coordinates everything is plotted in a normalized
// system, where the range is from 0.0 to 1.0 in the y axis, and in screen
// coordinates along the x axis.
if (!this->Storage->Axes.size())
if (this->Storage->Axes.empty())
{
return;
}
......
......@@ -486,7 +486,7 @@ void vtkChartXY::CalculateBarPlots()
bars.push_back(bar);
}
}
if (bars.size())
if (!bars.empty())
{
// We have some bar plots - work out offsets etc.
float barWidth = 0.1;
......
......@@ -654,7 +654,7 @@ void vtkChartXYZ::DrawTickMarks(vtkContext2D *painter)
}
// re-apply the Box matrix and draw the tick marks as points
if (tickPoints.size() != 0)
if (!tickPoints.empty())
{
context->PushMatrix();
context->AppendTransform(this->Box.GetPointer());
......
......@@ -494,7 +494,7 @@ public:
return -1;
}
if (this->SortedPoints.size() == 0)
if (this->SortedPoints.empty())
{
float* data = reinterpret_cast<float*>(this->Points->GetVoidPointer(0));
this->SortedPoints.Initialize(reinterpret_cast<vtkVector2f*>(data),
......
......@@ -40,7 +40,7 @@ bool vtkPlotLine3D::Paint(vtkContext2D *painter)
// This is where everything should be drawn, or dispatched to other methods.
vtkDebugMacro(<< "Paint event called in vtkPlotLine3D.");
if (!this->Visible || this->Points.size() == 0)
if (!this->Visible || this->Points.empty())
{
return false;
}
......
......@@ -116,7 +116,7 @@ bool vtkPlotParallelCoordinates::Paint(vtkContext2D *painter)
painter->ApplyPen(this->Pen);
if (this->Storage->size() == 0)
if (this->Storage->empty())
{
return false;
}
......
......@@ -48,7 +48,7 @@ void vtkPlotPoints3D::PrintSelf(ostream &os, vtkIndent indent)
//-----------------------------------------------------------------------------
bool vtkPlotPoints3D::Paint(vtkContext2D *painter)
{
if (!this->Visible || this->Points.size() == 0)
if (!this->Visible || this->Points.empty())
{
return false;
}
......@@ -63,7 +63,7 @@ bool vtkPlotPoints3D::Paint(vtkContext2D *painter)
this->Update();
if (this->Points.size() > 0)
if (!this->Points.empty())
{
// Draw the points in 3d.
......
......@@ -76,7 +76,7 @@ bool vtkPlotSurface::Paint(vtkContext2D *painter)
context->ApplyPen(this->Pen.GetPointer());
// draw the surface
if (this->Surface.size() > 0)
if (!this->Surface.empty())
{
context->DrawTriangleMesh(this->Surface[0].GetData(),
static_cast<int>(this->Surface.size()),
......
......@@ -1180,11 +1180,11 @@ bool vtkScatterPlotMatrix::MouseButtonReleaseEvent(
}
if ((this->Private->AnimationPath.size() == 1 &&
this->Private->AnimationPath.back() != pos) ||
(this->Private->AnimationPath.size() == 0 && this->ActivePlot != pos))
(this->Private->AnimationPath.empty() && this->ActivePlot != pos))
{
this->Private->AnimationPath.push_back(pos);
}
if (this->Private->AnimationPath.size() > 0)
if (!this->Private->AnimationPath.empty())
{
this->InvokeEvent(vtkCommand::CreateTimerEvent);
this->StartAnimation(mouse.GetInteractor());
......@@ -1198,7 +1198,7 @@ bool vtkScatterPlotMatrix::MouseButtonReleaseEvent(
return true;
}
this->UpdateAnimationPath(pos);
if (this->Private->AnimationPath.size() > 0)
if (!this->Private->AnimationPath.empty())
{
this->InvokeEvent(vtkCommand::CreateTimerEvent);
this->StartAnimation(mouse.GetInteractor());
......@@ -1240,7 +1240,7 @@ vtkVector2i vtkScatterPlotMatrix::GetAnimationPathElement(vtkIdType i)
bool vtkScatterPlotMatrix::AddAnimationPath(const vtkVector2i &move)
{
vtkVector2i pos = this->ActivePlot;
if (this->Private->AnimationPath.size())
if (!this->Private->AnimationPath.empty())
{
pos = this->Private->AnimationPath.back();
}
......@@ -1258,7 +1258,7 @@ bool vtkScatterPlotMatrix::AddAnimationPath(const vtkVector2i &move)
bool vtkScatterPlotMatrix::BeginAnimationPath(vtkRenderWindowInteractor* interactor)
{
if (interactor && this->Private->AnimationPath.size())
if (interactor && !this->Private->AnimationPath.empty())
{
this->StartAnimation(interactor);
return true;
......
......@@ -85,7 +85,7 @@ int TestArrayAPI(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
array.TakeReference(vtkArray::CreateArray(*storage_type, value_types[value_type]));
test_expression(array);
test_expression(array->GetName() == "");
test_expression(array->GetName().empty());
array->SetName("foo");
test_expression(array->GetName() == "foo");
......
......@@ -319,7 +319,7 @@ int TestArrayAPISparse(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
std::vector<vtkSparseArray<double>::CoordinateT> badcoords =
array1D->GetUniqueCoordinates(5);
test_expression(badcoords.size() == 0);
test_expression(badcoords.empty());
test_expression(
errorObserver->GetErrorMessage().find(
"Dimension out-of-bounds.") != std::string::npos);
......
......@@ -149,7 +149,7 @@ const char* vtkAbstractArray::GetComponentName( vtkIdType component )
//----------------------------------------------------------------------------
bool vtkAbstractArray::HasAComponentName()
{
return (this->ComponentNames) ? ( this->ComponentNames->size() > 0 ) : 0;
return (this->ComponentNames) ? ( !this->ComponentNames->empty() ) : 0;
}
//----------------------------------------------------------------------------
......
......@@ -280,7 +280,7 @@ void vtkDataObjectTree::SetDataSetFrom(vtkDataObjectTreeIterator* iter,
vtkDataObjectTreeIndex index = iter->GetCurrentIndex();
if (index.size() == 0)
if (index.empty())
{
// Sanity check.
vtkErrorMacro("Invalid index returned by iterator.");
......@@ -351,7 +351,7 @@ vtkDataObject* vtkDataObjectTree::GetDataSet(vtkCompositeDataIterator* composite
vtkDataObjectTreeIndex index = iter->GetCurrentIndex();
if (index.size() == 0)
if (index.empty())
{
// Sanity check.
vtkErrorMacro("Invalid index returned by iterator.");
......@@ -393,7 +393,7 @@ vtkInformation* vtkDataObjectTree::GetMetaData(vtkCompositeDataIterator* composi
vtkDataObjectTreeIndex index = iter->GetCurrentIndex();
if (index.size() == 0)
if (index.empty())
{
// Sanity check.
vtkErrorMacro("Invalid index returned by iterator.");
......@@ -435,7 +435,7 @@ int vtkDataObjectTree::HasMetaData(vtkCompositeDataIterator* compositeIter)
vtkDataObjectTreeIndex index = iter->GetCurrentIndex();
if (index.size() == 0)
if (index.empty())
{
// Sanity check.
vtkErrorMacro("Invalid index returned by iterator.");
......
......@@ -2028,7 +2028,7 @@ void vtkDataSetAttributes::FieldList::UnionFieldList(vtkDataSetAttributes* dsa)
}
}
if (dsaPendingIndices.size() != 0)
if (!dsaPendingIndices.empty())
{
size_t old_size = dsaIndices.size();
size_t new_size = old_size + dsaPendingIndices.size();
......
......@@ -82,7 +82,7 @@ void vtkEdgeTablePoints::LoadFactor()
for(int i=0; i<size; i++)
{
numEntries += static_cast<vtkIdType>(PointVector[i].size());
if( PointVector[i].size() ) numBins++;
if( !PointVector[i].empty() ) numBins++;
cerr << PointVector[i].size() << ",";
}
cerr << "\n";
......@@ -151,7 +151,7 @@ void vtkEdgeTableEdge::LoadFactor()
{
VectorEdgeTableType v = Vector[i];
numEntry += static_cast<vtkIdType>(v.size());
if(v.size()) numBins++;
if(!v.empty()) numBins++;
}
cerr << "\n";
cerr << size << "," << numEntry << "," << numBins << "," << Modulo
......
......@@ -750,7 +750,7 @@ public:
// Public only for the vtkCompactHyperOctreeCursor.
int GetNumberOfNodes() VTK_OVERRIDE
{
assert("post: not_empty" && this->Nodes.size()>0);
assert("post: not_empty" && !this->Nodes.empty());
return static_cast<int>(this->Nodes.size());
}
......
......@@ -715,7 +715,7 @@ public:
// NB: Public only for the vtkCompactHyperTreeCursor.
vtkIdType GetNumberOfNodes() VTK_OVERRIDE
{
assert( "post: not_empty" && this->Nodes.size() > 0 );
assert( "post: not_empty" && !this->Nodes.empty() );
return static_cast<vtkIdType>( this->Nodes.size() );
}
......
......@@ -195,7 +195,7 @@ int vtkHyperTreeGrid::GetDataObjectType()
void vtkHyperTreeGrid::DeleteTrees()
{
if ( this->HyperTrees.size() )
if ( !this->HyperTrees.empty() )
{
vtkHyperTreeIterator it;
this->InitializeTreeIterator( it );
......@@ -232,7 +232,7 @@ void vtkHyperTreeGrid::CopyStructure( vtkDataSet* ds )
// Shallow copy and register new trees
this->HyperTrees = htg->HyperTrees;
if ( this->HyperTrees.size() )
if ( !this->HyperTrees.empty() )
{
vtkHyperTreeIterator it;
this->InitializeTreeIterator( it );
......@@ -481,7 +481,7 @@ void vtkHyperTreeGrid::SubdivideLeaf( vtkHyperTreeCursor* leaf, vtkIdType id )
//-----------------------------------------------------------------------------
void vtkHyperTreeGrid::Initialize()
{
if ( this->HyperTrees.size() )
if ( !this->HyperTrees.empty() )
{
vtkHyperTreeIterator it;
this->InitializeTreeIterator( it );
......
......@@ -198,7 +198,7 @@ const char *vtkPiecewiseFunction::GetType()
function_type = 0;
if( this->Internal->Nodes.size() )
if( !this->Internal->Nodes.empty() )
{
prev_value = this->Internal->Nodes[0]->Y;
}
......@@ -290,7 +290,7 @@ double *vtkPiecewiseFunction::GetDataPointer()
double vtkPiecewiseFunction::GetFirstNonZeroValue()
{
// Check if no points specified
if( this->Internal->Nodes.size() == 0 )
if( this->Internal->Nodes.empty() )
{
return 0;
}
......
......@@ -1955,7 +1955,7 @@ void vtkReebGraph::CloseStream()
if(!((aIt->second.first.size() == 1)&&(aIt->second.second.size() == 1)))
{
// not a deg-2 node
if(aIt->second.second.size())
if(!aIt->second.second.empty())
{
// start the sweep up
for(unsigned int i = 0; i < aIt->second.second.size(); i++)
......
......@@ -69,7 +69,7 @@ void vtkTreeBFSIterator::Initialize()
{
this->StartVertex = this->Tree->GetRoot();
}
while (this->Internals->Queue.size())
while (!this->Internals->Queue.empty())
{
this->Internals->Queue.pop();
}
......@@ -93,7 +93,7 @@ vtkIdType vtkTreeBFSIterator::NextInternal()
this->Internals->Queue.push(this->StartVertex);
}
while (this->Internals->Queue.size() > 0)
while (!this->Internals->Queue.empty())
{
vtkIdType currentId = this->Internals->Queue.front();
this->Internals->Queue.pop();
......
......@@ -87,7 +87,7 @@ void vtkTreeDFSIterator::Initialize()
this->StartVertex = this->Tree->GetRoot();
}
this->CurRoot = this->StartVertex;
while (this->Internals->Stack.size())
while (!this->Internals->Stack.empty())
{
this->Internals->Stack.pop();
}
......@@ -117,7 +117,7 @@ vtkIdType vtkTreeDFSIterator::NextInternal()
{
while (this->Color->GetValue(this->StartVertex) != this->BLACK)
{
while (this->Internals->Stack.size() > 0)
while (!this->Internals->Stack.empty())
{
// Pop the current position off the stack
vtkTreeDFSIteratorPosition pos = this->Internals->Stack.top();
......
......@@ -31,7 +31,7 @@ public:
void Initialize(const std::vector<int>* numBlocks)
{
assert(numBlocks && numBlocks->size()>=1);
assert(numBlocks && !numBlocks->empty());
this->Level = 0;
this->Index = -1;
this->NumBlocks = numBlocks;
......@@ -81,7 +81,7 @@ public:
AMRLoadedDataIndexIterator(){}
void Initialize(const std::vector<int>* numBlocks, const vtkAMRDataInternals::BlockList* dataBlocks)
{
assert(numBlocks && numBlocks->size()>=1);
assert(numBlocks && !numBlocks->empty());
this->Level = 0;
this->InternalIdx = -1;
this->NumBlocks = numBlocks;
......
......@@ -120,7 +120,7 @@ int vtkMultiTimeStepAlgorithm::ProcessRequest(
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
vtkDataObject* inData = inInfo->Get(vtkDataObject::DATA_OBJECT());
if(this->UpdateTimeSteps.size()==0)
if(this->UpdateTimeSteps.empty())
{
vtkErrorMacro("No temporal data has been requested. ");
return 0;
......
......@@ -71,7 +71,7 @@ int vtkQuaternionInterpolator::GetNumberOfQuaternions()
//----------------------------------------------------------------------------
double vtkQuaternionInterpolator::GetMinimumT()
{
if (this->QuaternionList->size() > 0)
if (!this->QuaternionList->empty())
{
return this->QuaternionList->front().Time;
}
......@@ -85,7 +85,7 @@ double vtkQuaternionInterpolator::GetMinimumT()
//----------------------------------------------------------------------------
double vtkQuaternionInterpolator::GetMaximumT()
{
if (this->QuaternionList->size() > 0)
if (!this->QuaternionList->empty())
{
return this->QuaternionList->back().Time;
}
......
......@@ -343,7 +343,7 @@ void vtkAMRCutPlane::ExtractPointDataFromGrid(
assert("pre: target point data is NULL!" && (PD != NULL) );
if( (grid->GetPointData()->GetNumberOfArrays()==0) ||
(gridPntMapping.size() == 0))
(gridPntMapping.empty()))
{
// Nothing to extract short-circuit here
return;
......@@ -389,7 +389,7 @@ void vtkAMRCutPlane::ExtractCellDataFromGrid(
assert("pre: target cell data is NULL!" && (CD != NULL) );
if( (grid->GetCellData()->GetNumberOfArrays()==0) ||
(cellIdxList.size()==0) )
(cellIdxList.empty()) )
{
// Nothing to extract short-circuit here
return;
......
......@@ -348,7 +348,7 @@ vtkDataObject * vtkDataObjectGenerator::CreateOutputDataObjects(
{
case -1: //top holder it should hold a single data set, use it
{
if (!structure->children.size())
if (structure->children.empty())
{
return NULL;
}
......@@ -414,7 +414,7 @@ int vtkDataObjectGenerator::RequestInformation(vtkInformation *req,
return VTK_OK;
}
if (!this->Structure->children.size())
if (this->Structure->children.empty())
{
vtkErrorMacro("Program was invalid.");
return VTK_ERROR;
......@@ -615,7 +615,7 @@ vtkDataObject * vtkDataObjectGenerator::FillOutputDataObjects(
{
case -1: //top level is a holder, use the single data set inside instead
{
if (!structure->children.size())
if (structure->children.empty())
{
return NULL;
}
......
......@@ -132,7 +132,7 @@ int vtkExtractBlock::RequestData(
iter->VisitOnlyLeavesOff();
for (iter->InitTraversal();
!iter->IsDoneWithTraversal() && this->ActiveIndices->size()>0;
!iter->IsDoneWithTraversal() && !this->ActiveIndices->empty();
iter->GoToNextItem())
{
if (this->ActiveIndices->find(iter->GetCurrentFlatIndex()) !=
......
......@@ -478,7 +478,7 @@ int TestLagrangianIntegrationModel(int, char*[])
delete part;
return EXIT_FAILURE;
}
if (particles.size() != 0 || passThroughParticles.size() != 0)
if (!particles.empty() || !passThroughParticles.empty())
{
std::cerr << "Unexpected new particles created with SurfaceTypeModel"
<< std::endl;
......@@ -516,7 +516,7 @@ int TestLagrangianIntegrationModel(int, char*[])
delete part;
return EXIT_FAILURE;
}
if (particles.size() != 0 || passThroughParticles.size() != 0)
if (!particles.empty() || !passThroughParticles.empty())
{
std::cerr << "Unexpected number particles created with SurfaceTypeTerm"
<< std::endl;
......@@ -554,7 +554,7 @@ int TestLagrangianIntegrationModel(int, char*[])
delete part;
return EXIT_FAILURE;
}
if (particles.size() != 0 || passThroughParticles.size() != 0)
if (!particles.empty() || !passThroughParticles.empty())
{
std::cerr << "Unexpected number particles created with SurfaceTypeBounce:"
<< particles.size() << " " << passThroughParticles.size() << std::endl;
......@@ -593,7 +593,7 @@ int TestLagrangianIntegrationModel(int, char*[])
delete part;
return EXIT_FAILURE;
}
if (particles.size() != 0 || passThroughParticles.size() != 0)
if (!particles.empty() || !passThroughParticles.empty())
{
std::cerr << "Unexpected number particles created with SurfaceTypeBounce perforation:"
<< particles.size() << " " << passThroughParticles.size() << std::endl;
......@@ -634,7 +634,7 @@ int TestLagrangianIntegrationModel(int, char*[])
delete part;
return EXIT_FAILURE;
}
if (particles.size() != 2 || passThroughParticles.size() != 0)
if (particles.size() != 2 || !passThroughParticles.empty())
{
std::cerr << "Unexpected number particles created with SurfaceTypeBreak:"
<< particles.size() << " " << passThroughParticles.size() << std::endl;
......@@ -677,7 +677,7 @@ int TestLagrangianIntegrationModel(int, char*[])
delete part;
return EXIT_FAILURE;
}
if (particles.size() != 0 || passThroughParticles.size() != 1)
if (!particles.empty() || passThroughParticles.size() != 1)
{
std::cerr << "Unexpected number particles created with SurfaceTypePass: "
<< particles.size() << " " << passThroughParticles.size() << std::endl;
......@@ -719,7 +719,7 @@ int TestLagrangianIntegrationModel(int, char*[])
delete part;
return EXIT_FAILURE;
}
if (particles.size() != 0 || passThroughParticles.size() != 0)
if (!particles.empty() || !passThroughParticles.empty())
{
std::cerr << "Unexpected new particles created with SurfaceTypeModel Cleared"
<< particles.size() << " " << passThroughParticles.size() << std::endl;
......
......@@ -432,7 +432,7 @@ void vtkCachingInterpolatedVelocityField::PrintSelf(ostream& os, vtkIndent inden
{
this->Superclass::PrintSelf(os, indent);
if (Weights.size()>0)
if (!Weights.empty())
{
os << indent << "Weights: " << &this->Weights[0] << endl;
}
......
......@@ -80,7 +80,7 @@ namespace
//return the interval i, such that a belongs to the interval (A[i],A[i+1]]
inline int FindInterval(double a, const std::vector<double>& A)
{
if(A.size() == 0 || a < A[0])
if(A.empty() || a < A[0])
{
return -1;
}
......@@ -816,7 +816,7 @@ vtkPolyData* vtkParticleTracerBase::Execute(vtkInformationVector** inputVector)
{
Assert(!this->HasCache); //shouldn't have cache if restarting
int seedPointId=0;
if (!(this->StaticSeeds && this->AllFixedGeometry && this->LocalSeeds.size()==0))
if (!(this->StaticSeeds && this->AllFixedGeometry && this->LocalSeeds.empty()))
{
// wipe the list and reclassify for each injection
this->LocalSeeds.clear();
......@@ -880,7 +880,7 @@ vtkPolyData* vtkParticleTracerBase::Execute(vtkInformationVector** inputVector)
// Particles might have been deleted during the first pass as they move
// out of domain or age. Before adding any new particles that are sent
// to us, we must know the starting point ready for the next pass
bool list_valid = (this->ParticleHistories.size()>0);
bool list_valid = (!this->ParticleHistories.empty());
if (list_valid)
{
// point to one before the end
......
......@@ -779,7 +779,7 @@ int vtkTemporalStreamTracer::GenerateOutput(vtkInformationVector** inputVector,
if (this->ReinjectionFlag)
{
int seedPointId=0;
if (this->StaticSeeds && this->AllFixedGeometry && this->LocalSeeds.size()==0)
if (this->StaticSeeds && this->AllFixedGeometry && this->LocalSeeds.empty())
{
for (unsigned int i=0; i<SeedSources.size(); i++)
{
......@@ -906,7 +906,7 @@ int vtkTemporalStreamTracer::GenerateOutput(vtkInformationVector** inputVector,
// Particles might have been deleted during the first pass as they move
// out of domain or age. Before adding any new particles that are sent
// to us, we must know the starting point ready for the second pass
bool list_valid = (this->ParticleHistories.size()>0);
bool list_valid = (!this->ParticleHistories.empty());
if (list_valid) {
// point to one before the end
it_first = --this->ParticleHistories.end();
......@@ -923,7 +923,7 @@ int vtkTemporalStreamTracer::GenerateOutput(vtkInformationVector** inputVector,
this->MPISendList.clear();
int assigned;
// classify all the ones we received