Skip to content
Permalink
Browse files

Use .empty() instead of .size() > 0/.size() >=1/etc

Possibly faster, and clearer to read
  • Loading branch information
nyalldawson committed Sep 11, 2017
1 parent 2a33844 commit c17978043c4a9c14f8771a02152ae70d0bd4359c
Showing with 98 additions and 96 deletions.
  1. +1 −1 src/analysis/interpolation/qgsinterpolator.cpp
  2. +1 −1 src/analysis/openstreetmap/qgsosmimport.cpp
  3. +2 −2 src/app/composer/qgsattributeselectiondialog.cpp
  4. +1 −1 src/app/composer/qgscomposer.cpp
  5. +8 −8 src/app/dwg/qgsdwgimporter.cpp
  6. +3 −3 src/app/qgisapp.cpp
  7. +1 −1 src/app/qgsattributetabledialog.cpp
  8. +2 −2 src/app/qgsmaptoolmeasureangle.cpp
  9. +1 −1 src/app/qgsmaptooloffsetcurve.cpp
  10. +2 −2 src/app/qgsmaptoolrotatelabel.cpp
  11. +1 −1 src/app/qgsmeasuredialog.cpp
  12. +1 −1 src/app/qgsmeasuretool.cpp
  13. +1 −1 src/app/qgsmergeattributesdialog.cpp
  14. +6 −6 src/app/qgsprojectproperties.cpp
  15. +2 −2 src/core/auth/qgsauthmanager.cpp
  16. +1 −1 src/core/composer/qgscomposermap.cpp
  17. +1 −1 src/core/composer/qgscomposermousehandles.cpp
  18. +2 −2 src/core/composer/qgscomposermultiframe.cpp
  19. +1 −1 src/core/composer/qgscomposition.cpp
  20. +1 −1 src/core/dxf/qgsdxfexport.cpp
  21. +2 −2 src/core/dxf/qgsdxfpaintengine.cpp
  22. +1 −1 src/core/geometry/qgscircularstring.cpp
  23. +5 −5 src/core/geometry/qgscompoundcurve.cpp
  24. +1 −1 src/core/geometry/qgscurvepolygon.cpp
  25. +2 −2 src/core/geometry/qgsgeometry.cpp
  26. +1 −1 src/core/geometry/qgsgeometrycollection.cpp
  27. +1 −1 src/core/geometry/qgsgeos.cpp
  28. +1 −1 src/core/qgsclipper.cpp
  29. +5 −3 src/core/qgscolorramp.cpp
  30. +1 −1 src/core/qgseditformconfig.cpp
  31. +1 −1 src/core/qgsgml.cpp
  32. +1 −1 src/core/qgslegendrenderer.cpp
  33. +3 −3 src/core/qgsofflineediting.cpp
  34. +5 −5 src/core/qgsogcutils.cpp
  35. +1 −1 src/core/qgsvectorfilewriter.cpp
  36. +3 −3 src/core/qgsvectorlayer.cpp
  37. +1 −1 src/core/qgsvectorlayereditutils.cpp
  38. +1 −1 src/core/qgsvectorlayerfeatureiterator.cpp
  39. +1 −1 src/core/raster/qgsmultibandcolorrenderer.cpp
  40. +1 −1 src/core/symbology/qgsarrowsymbollayer.cpp
  41. +1 −1 src/core/symbology/qgssymbol.cpp
  42. +2 −2 src/gui/auth/qgsauthauthoritieseditor.cpp
  43. +1 −1 src/gui/auth/qgsauthcertificateinfo.cpp
  44. +2 −2 src/gui/auth/qgsauthidentitieseditor.cpp
  45. +2 −2 src/gui/auth/qgsauthserverseditor.cpp
  46. +2 −2 src/gui/auth/qgsauthtrustedcasdialog.cpp
  47. +2 −2 src/gui/ogr/qgsvectorlayersaveasdialog.cpp
  48. +2 −2 src/gui/qgsowssourceselect.cpp
  49. +1 −1 src/gui/qgsrubberband.cpp
  50. +1 −1 src/providers/ogr/qgsogrdataitems.cpp
  51. +1 −1 src/providers/postgres/qgspgtablemodel.cpp
  52. +3 −3 src/providers/spatialite/qgsspatialiteprovider.cpp
  53. +1 −1 src/providers/spatialite/qgsspatialitetablemodel.cpp
@@ -37,7 +37,7 @@ QgsInterpolator::QgsInterpolator()

int QgsInterpolator::cacheBaseData()
{
if ( mLayerData.size() < 1 )
if ( mLayerData.empty() )
{
return 0;
}
@@ -136,7 +136,7 @@ bool QgsOSMXmlImport::createDatabase()
{
QString version = QString::fromUtf8( results[1] );
QStringList parts = version.split( ' ', QString::SkipEmptyParts );
if ( parts.size() >= 1 )
if ( !parts.empty() )
{
QStringList verparts = parts[0].split( '.', QString::SkipEmptyParts );
above41 = verparts.size() >= 2 && ( verparts[0].toInt() > 4 || ( verparts[0].toInt() == 4 && verparts[1].toInt() >= 1 ) );
@@ -340,7 +340,7 @@ void QgsAttributeSelectionDialog::on_mColumnUpPushButton_clicked()
{
//move selected row up
QItemSelection viewSelection( mColumnsTableView->selectionModel()->selection() );
if ( viewSelection.size() > 0 )
if ( !viewSelection.empty() )
{
int selectedRow = viewSelection.indexes().at( 0 ).row();
mColumnModel->moveRow( selectedRow, QgsComposerAttributeTableColumnModelV2::ShiftUp );
@@ -351,7 +351,7 @@ void QgsAttributeSelectionDialog::on_mColumnDownPushButton_clicked()
{
//move selected row down
QItemSelection viewSelection( mColumnsTableView->selectionModel()->selection() );
if ( viewSelection.size() > 0 )
if ( !viewSelection.empty() )
{
int selectedRow = viewSelection.indexes().at( 0 ).row();
mColumnModel->moveRow( selectedRow, QgsComposerAttributeTableColumnModelV2::ShiftDown );
@@ -2136,7 +2136,7 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
return;
}
QStringList s = dlg.selectedFiles();
if ( s.size() < 1 || s.at( 0 ).isEmpty() )
if ( s.empty() || s.at( 0 ).isEmpty() )
{
return;
}
@@ -811,7 +811,7 @@ void QgsDwgImporter::addLType( const DRW_LType &data )
}

QString typeName( data.name.c_str() ), dash( "" );
if ( upath.size() > 0 )
if ( !upath.empty() )
{
QStringList l;
if ( upath[0] < 0 )
@@ -1486,7 +1486,7 @@ void QgsDwgImporter::addLWPolyline( const DRW_LWPolyline &data )
.arg( p1.asWkt() ), 5
);

if ( s.size() > 0 && ( width != staWidth || width != endWidth || hadBulge != hasBulge ) )
if ( !s.empty() && ( width != staWidth || width != endWidth || hadBulge != hasBulge ) )
{
if ( hadBulge )
{
@@ -1536,7 +1536,7 @@ void QgsDwgImporter::addLWPolyline( const DRW_LWPolyline &data )

if ( staWidth == endWidth )
{
if ( s.size() == 0 )
if ( s.empty() )
{
s << p0;
hadBulge = hasBulge;
@@ -1604,7 +1604,7 @@ void QgsDwgImporter::addLWPolyline( const DRW_LWPolyline &data )
}
}

if ( s.size() > 0 )
if ( !s.empty() )
{
if ( hadBulge )
{
@@ -1685,7 +1685,7 @@ void QgsDwgImporter::addPolyline( const DRW_Polyline &data )
.arg( p1.asWkt() ), 5
);

if ( s.size() > 0 && ( width != staWidth || width != endWidth || hadBulge != hasBulge ) )
if ( !s.empty() && ( width != staWidth || width != endWidth || hadBulge != hasBulge ) )
{
if ( hadBulge )
{
@@ -1737,7 +1737,7 @@ void QgsDwgImporter::addPolyline( const DRW_Polyline &data )

if ( staWidth == endWidth )
{
if ( s.size() == 0 )
if ( s.empty() )
{
s << p0;
hadBulge = hasBulge;
@@ -1810,7 +1810,7 @@ void QgsDwgImporter::addPolyline( const DRW_Polyline &data )
}
}

if ( s.size() > 0 )
if ( !s.empty() )
{
if ( hadBulge )
{
@@ -2052,7 +2052,7 @@ void QgsDwgImporter::addSpline( const DRW_Spline *data )
}
}

if ( cps.size() > 0 && data->flags & 1 )
if ( !cps.empty() && data->flags & 1 )
{
for ( int i = 0; i < data->degree; ++i )
cps.push_back( cps[i] );
@@ -4149,7 +4149,7 @@ void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )
QStringList sublayers = layer->subLayers();
QgsDebugMsg( QString( "raster has %1 sublayers" ).arg( layer->subLayers().size() ) );

if ( sublayers.size() < 1 )
if ( sublayers.empty() )
return;

// if promptLayers=Load all, load all sublayers without prompting
@@ -4256,7 +4256,7 @@ void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )
bool QgisApp::shouldAskUserForGDALSublayers( QgsRasterLayer *layer )
{
// return false if layer is empty or raster has no sublayers
if ( !layer || layer->providerType() != QLatin1String( "gdal" ) || layer->subLayers().size() < 1 )
if ( !layer || layer->providerType() != QLatin1String( "gdal" ) || layer->subLayers().empty() )
return false;

QgsSettings settings;
@@ -6151,7 +6151,7 @@ void QgisApp::refreshFeatureActions()

//add actions registered in QgsMapLayerActionRegistry
QList<QgsMapLayerAction *> registeredActions = QgsGui::mapLayerActionRegistry()->mapLayerActions( vlayer );
if ( !actions.isEmpty() && registeredActions.size() > 0 )
if ( !actions.isEmpty() && !registeredActions.empty() )
{
//add a separator between user defined and standard actions
mFeatureActionMenu->addSeparator();
@@ -841,7 +841,7 @@ void QgsAttributeTableDialog::on_mActionRemoveAttribute_triggered()
if ( dialog.exec() == QDialog::Accepted )
{
QList<int> attributes = dialog.selectedAttributes();
if ( attributes.size() < 1 )
if ( attributes.empty() )
{
return;
}
@@ -44,7 +44,7 @@ QgsMapToolMeasureAngle::~QgsMapToolMeasureAngle()

void QgsMapToolMeasureAngle::canvasMoveEvent( QgsMapMouseEvent *e )
{
if ( !mRubberBand || mAnglePoints.size() < 1 || mAnglePoints.size() > 2 )
if ( !mRubberBand || mAnglePoints.empty() || mAnglePoints.size() > 2 )
{
return;
}
@@ -89,7 +89,7 @@ void QgsMapToolMeasureAngle::canvasReleaseEvent( QgsMapMouseEvent *e )
mAnglePoints.clear();
}

if ( mAnglePoints.size() < 1 )
if ( mAnglePoints.empty() )
{
if ( !mResultDisplay )
{
@@ -284,7 +284,7 @@ QgsGeometry QgsMapToolOffsetCurve::createOriginGeometry( QgsVectorLayer *vl, con

//for background layers, try to merge selected entries together if snapped feature is contained in selection
const QgsFeatureIds &selection = vl->selectedFeatureIds();
if ( selection.size() < 1 || !selection.contains( match.featureId() ) )
if ( selection.empty() || !selection.contains( match.featureId() ) )
{
return convertToSingleLine( snappedFeature.geometry(), partVertexNr, mMultiPartGeometry );
}
@@ -189,7 +189,7 @@ QgsRubberBand *QgsMapToolRotateLabel::createRotationPreviewBox()
{
delete mRotationPreviewBox;
QVector< QgsPointXY > boxPoints = mCurrentLabel.pos.cornerPoints;
if ( boxPoints.size() < 1 )
if ( boxPoints.empty() )
{
return nullptr;
}
@@ -210,7 +210,7 @@ void QgsMapToolRotateLabel::setRotationPreviewBox( double rotation )

mRotationPreviewBox->reset();
QVector< QgsPointXY > boxPoints = mCurrentLabel.pos.cornerPoints;
if ( boxPoints.size() < 1 )
if ( boxPoints.empty() )
{
return;
}
@@ -154,7 +154,7 @@ void QgsMeasureDialog::mouseMove( const QgsPointXY &point )
double area = mDa.measurePolygon( tmpPoints );
editTotal->setText( formatArea( area ) );
}
else if ( !mMeasureArea && mTool->points().size() >= 1 )
else if ( !mMeasureArea && !mTool->points().empty() )
{
QList< QgsPointXY > tmpPoints = mTool->points();
QgsPointXY p1( tmpPoints.at( tmpPoints.size() - 1 ) ), p2( point );
@@ -222,7 +222,7 @@ void QgsMeasureTool::undo()
{
if ( mRubberBand )
{
if ( mPoints.size() < 1 )
if ( mPoints.empty() )
{
return;
}
@@ -524,7 +524,7 @@ void QgsMergeAttributesDialog::createRubberBandForFeature( QgsFeatureId featureI

QgsAttributes QgsMergeAttributesDialog::mergedAttributes() const
{
if ( mFeatureList.size() < 1 )
if ( mFeatureList.empty() )
{
return QgsAttributes();
}
@@ -1381,7 +1381,7 @@ void QgsProjectProperties::on_mAddWMSComposerButton_clicked()
QString name = QInputDialog::getItem( this, tr( "Select print composer" ), tr( "Composer Title" ), composerTitles, 0, false, &ok );
if ( ok )
{
if ( mComposerListWidget->findItems( name, Qt::MatchExactly ).size() < 1 )
if ( mComposerListWidget->findItems( name, Qt::MatchExactly ).empty() )
{
mComposerListWidget->addItem( name );
}
@@ -1407,7 +1407,7 @@ void QgsProjectProperties::on_mAddLayerRestrictionButton_clicked()
QStringList::const_iterator layerIt = layerNames.constBegin();
for ( ; layerIt != layerNames.constEnd(); ++layerIt )
{
if ( mLayerRestrictionsListWidget->findItems( *layerIt, Qt::MatchExactly ).size() < 1 )
if ( mLayerRestrictionsListWidget->findItems( *layerIt, Qt::MatchExactly ).empty() )
{
mLayerRestrictionsListWidget->addItem( *layerIt );
}
@@ -1417,7 +1417,7 @@ void QgsProjectProperties::on_mAddLayerRestrictionButton_clicked()
QStringList::const_iterator groupIt = groups.constBegin();
for ( ; groupIt != groups.constEnd(); ++groupIt )
{
if ( mLayerRestrictionsListWidget->findItems( *groupIt, Qt::MatchExactly ).size() < 1 )
if ( mLayerRestrictionsListWidget->findItems( *groupIt, Qt::MatchExactly ).empty() )
{
mLayerRestrictionsListWidget->addItem( *groupIt );
}
@@ -1506,7 +1506,7 @@ void QgsProjectProperties::on_pbnLaunchOWSChecker_clicked()
duplicateNames << name;
}

if ( duplicateNames.size() != 0 )
if ( !duplicateNames.empty() )
{
QString nameMessage = "<h1>" + tr( "Some layers and groups have the same name or short name" ) + "</h1>";
nameMessage += "<h2>" + tr( "Duplicate names:" ) + "</h2>";
@@ -1518,7 +1518,7 @@ void QgsProjectProperties::on_pbnLaunchOWSChecker_clicked()
teOWSChecker->setHtml( teOWSChecker->toHtml() + "<h1>" + tr( "All names and short names of layer and group are unique" ) + "</h1>" );
}

if ( regExpMessages.size() != 0 )
if ( !regExpMessages.empty() )
{
QString encodingMessage = "<h1>" + tr( "Some layer short names have to be updated:" ) + "</h1><ul><li>" + regExpMessages.join( QStringLiteral( "</li><li>" ) ) + "</li></ul>";
teOWSChecker->setHtml( teOWSChecker->toHtml() + encodingMessage );
@@ -1528,7 +1528,7 @@ void QgsProjectProperties::on_pbnLaunchOWSChecker_clicked()
teOWSChecker->setHtml( teOWSChecker->toHtml() + "<h1>" + tr( "All layer short names are well formed" ) + "</h1>" );
}

if ( encodingMessages.size() != 0 )
if ( !encodingMessages.empty() )
{
QString encodingMessage = "<h1>" + tr( "Some layer encodings are not set:" ) + "</h1><ul><li>" + encodingMessages.join( QStringLiteral( "</li><li>" ) ) + "</li></ul>";
teOWSChecker->setHtml( teOWSChecker->toHtml() + encodingMessage );
@@ -2235,7 +2235,7 @@ bool QgsAuthManager::rebuildIgnoredSslErrorCache()

bool QgsAuthManager::storeCertAuthorities( const QList<QSslCertificate> &certs )
{
if ( certs.size() < 1 )
if ( certs.isEmpty() )
{
QgsDebugMsg( "Passed certificate list has no certs" );
return false;
@@ -2542,7 +2542,7 @@ QgsAuthCertUtils::CertTrustPolicy QgsAuthManager::getCertTrustPolicy( const QSsl

bool QgsAuthManager::removeCertTrustPolicies( const QList<QSslCertificate> &certs )
{
if ( certs.size() < 1 )
if ( certs.empty() )
{
QgsDebugMsg( "Passed certificate list has no certs" );
return false;
@@ -1796,7 +1796,7 @@ void QgsComposerMap::transformShift( double &xShift, double &yShift ) const
QPointF QgsComposerMap::mapToItemCoords( QPointF mapCoords ) const
{
QPolygonF mapPoly = transformedMapPolygon();
if ( mapPoly.size() < 1 )
if ( mapPoly.empty() )
{
return QPointF( 0, 0 );
}
@@ -1373,7 +1373,7 @@ void QgsComposerMouseHandles::checkNearestItem( double checkCoord, const QMap< d

bool QgsComposerMouseHandles::nearestItem( const QMap< double, const QgsComposerItem * > &coords, double value, double &nearestValue ) const
{
if ( coords.size() < 1 )
if ( coords.empty() )
{
return false;
}
@@ -68,7 +68,7 @@ void QgsComposerMultiFrame::setResizeMode( ResizeMode mode )

void QgsComposerMultiFrame::recalculateFrameSizes()
{
if ( mFrameItems.size() < 1 )
if ( mFrameItems.empty() )
{
return;
}
@@ -182,7 +182,7 @@ void QgsComposerMultiFrame::recalculateFrameSizes()

void QgsComposerMultiFrame::recalculateFrameRects()
{
if ( mFrameItems.size() < 1 )
if ( mFrameItems.empty() )
{
//no frames, nothing to do
return;
@@ -2200,7 +2200,7 @@ QGraphicsLineItem *QgsComposition::nearestSnapLine( const bool horizontal, const
int QgsComposition::boundingRectOfSelectedItems( QRectF &bRect )
{
QList<QgsComposerItem *> selectedItems = selectedComposerItems();
if ( selectedItems.size() < 1 )
if ( selectedItems.empty() )
{
return 1;
}
@@ -1071,7 +1071,7 @@ void QgsDxfExport::writeEntities()
else
{
QgsSymbolList symbolList = renderer->symbolsForFeature( fet, ctx );
if ( symbolList.size() < 1 )
if ( symbolList.empty() )
{
continue;
}
@@ -160,10 +160,10 @@ void QgsDxfPaintEngine::endPolygon()

void QgsDxfPaintEngine::endCurve()
{
if ( mCurrentCurve.size() < 1 )
if ( mCurrentCurve.empty() )
return;

if ( mCurrentPolygon.size() < 1 )
if ( mCurrentPolygon.empty() )
{
mCurrentCurve.clear();
return;
@@ -435,7 +435,7 @@ void QgsCircularString::setPoints( const QgsPointSequence &points )
{
clearCache();

if ( points.size() < 1 )
if ( points.empty() )
{
mWkbType = QgsWkbTypes::Unknown;
mX.clear();

0 comments on commit c179780

Please sign in to comment.
You can’t perform that action at this time.