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

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() );
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment