Opened 9 months ago

Last modified 3 months ago

#860 new defect

Prefer empty to size of zero

Reported by: goatbar Owned by: geos-devel@…
Priority: major Milestone: 3.6.4
Component: Default Version: 3.6.2
Severity: Unassigned Keywords:
Cc:

Description

double
ElevationMatrixCell::getAvg() const
{
        return  zvals.size() ?
                ztot / static_cast<double>(zvals.size()) :
                DoubleNotANumber;
}

Should become:

double
ElevationMatrixCell::getAvg() const
{
    return !zvals.empty() ? ztot / static_cast<double>(zvals.size())
                        : DoubleNotANumber;
}

or better yet, drop the not (!) in the test.

double
ElevationMatrixCell::getAvg() const
{
    return zvals.empty()
        ? DoubleNotANumber
        : ztot / static_cast<double>(zvals.size()) ;
}

Change History (2)

comment:1 Changed 8 months ago by goatbar

And there are some easy to find instances of the same thing:

find . -name \*.cpp | xargs egrep '[.]size()' | egrep '== *0|0 *=='
./geomgraph/EdgeEndStar.cpp:	if (edgeMap.size()==0) return nullCoord;
./geomgraph/EdgeEndStar.cpp:	if (edgeMap.size()==0) return true;
./operation/buffer/SubgraphDepthLocater.cpp:	if (stabbedSegments.size()==0) return 0;
./operation/overlay/LineBuilder.cpp:	if ( v3d.size() == 0 )
./linearref/ExtractLineByLocation.cpp:	if (newCoordinateArray.size() == 0)

comment:2 Changed 3 months ago by robe

Milestone: 3.6.33.6.4
Note: See TracTickets for help on using tickets.