Opened 3 years ago

Closed 3 years ago

#6687 closed task (fixed)

Prefer !container.empty() to container.size() > 0

Reported by: Kurt Schwehr Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: unspecified
Severity: normal Keywords:
Cc:

Description

It's less critical for containers where the size check is O(1), but GDAL should just always use .empty()

find . -name \*.cpp | xargs egrep '\.size\(\) *> *0'  | wc -l
     142
find . -name \*.cpp | xargs egrep '\.size\(\) *(>=|>) *0' 
./apps/gdal_rasterize_lib.cpp:            if( adfBurnValues.size() > 0 )
./apps/gdal_rasterize_lib.cpp:                if( adfBurnValues.size() > 0 )
./apps/nearblack_lib.cpp:            if ( psOptions->oColors.size() > 0 &&
./frmts/adrg/adrgdataset.cpp:    if (osGENFileName.size() > 0 && osIMGFileName.size() > 0)
./frmts/adrg/adrgdataset.cpp:    if (osGENFileName.size() > 0 &&
./frmts/adrg/adrgdataset.cpp:        osIMGFileName.size() > 0)
./frmts/adrg/srpdataset.cpp:    if (osGENFileName.size() > 0 && osIMGFileName.size() > 0)
./frmts/adrg/srpdataset.cpp:    if (osGENFileName.size() > 0 &&
./frmts/adrg/srpdataset.cpp:        osIMGFileName.size() > 0)
./frmts/bsb/bsbdataset.cpp:                 && osPP.size() > 0 )
./frmts/bsb/bsbdataset.cpp:                 && osPP.size() > 0 )
./frmts/bsb/bsbdataset.cpp:        else if( STARTS_WITH_CI(pszPR, "PR=POLYCONIC") && osPP.size() > 0 )
./frmts/bsb/bsbdataset.cpp:                 && osPP.size() > 0 && pszKNQ != NULL )
./frmts/bsb/bsbdataset.cpp:            if( osP2.size() > 0 && osP3.size() > 0 )

Change History (4)

comment:1 Changed 3 years ago by Kurt Schwehr

Starter commit: r35775 for kml driver

comment:2 Changed 3 years ago by Kurt Schwehr

r35837 geojson driver

comment:3 Changed 3 years ago by Even Rouault

In 36913:

Add scripts/fix_container_dot_size_zero.sh (refs #6687)

comment:4 Changed 3 years ago by Even Rouault

Resolution: fixed
Status: newclosed

The scripts/fix_container_dot_size_zero.sh can be used to detect and automatically fix those cases. Note: It is not added in a CI env. Must be manually passed

Note: See TracTickets for help on using tickets.