Skip to content

Commit

Permalink
Misc optimisations identified by clazy:
Browse files Browse the repository at this point in the history
- call reserve on container classes where applicable
- make sure Q_FOREACH uses references
- remove dynamic casts to base classes
- fix some implicit bool conversions
  • Loading branch information
nyalldawson committed Oct 5, 2015
1 parent 890dce8 commit 0caf944
Show file tree
Hide file tree
Showing 93 changed files with 170 additions and 96 deletions.
2 changes: 1 addition & 1 deletion python/core/geometry/qgsgeometry.sip
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ class QgsGeometry
public:
Error();
Error( QString m );
Error( QString m, QgsPoint p );
Error( QString m, const QgsPoint& p );

QString what();
QgsPoint where();
Expand Down
4 changes: 2 additions & 2 deletions python/core/qgslegendsettings.sip
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class QgsLegendSettings
int columnCount() const;
void setColumnCount( int c );

int splitLayer() const;
bool splitLayer() const;
void setSplitLayer( bool s );

int equalColumnWidth() const;
bool equalColumnWidth() const;
void setEqualColumnWidth( bool s );

QColor fontColor() const;
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class QgsVectorLayer : QgsMapLayer
struct RangeData
{
RangeData();
RangeData( QVariant theMin, QVariant theMax, QVariant theStep );
RangeData( const QVariant& theMin, const QVariant& theMax, const QVariant& theStep );

QVariant mMin;
QVariant mMax;
Expand Down
3 changes: 2 additions & 1 deletion python/core/symbology-ng/qgsheatmaprenderer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class QgsHeatmapRenderer : QgsFeatureRendererV2
* @see setInvertRamp
* @see colorRamp
*/
double invertRamp() const;
bool invertRamp() const;

/** Sets whether the ramp is inverted
* @param invert set to true to invert color ramp
* @see invertRamp
Expand Down
2 changes: 1 addition & 1 deletion python/core/symbology-ng/qgsrendererv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class QgsFeatureRendererV2
bool drawVertexMarker );

//! render editing vertex marker at specified point
void renderVertexMarker( QPointF& pt, QgsRenderContext& context );
void renderVertexMarker( const QPointF& pt, QgsRenderContext& context );
//! render editing vertex marker for a polyline
void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
//! render editing vertex marker for a polygon
Expand Down
2 changes: 1 addition & 1 deletion python/core/symbology-ng/qgssymbollayerv2utils.sip
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class QgsSymbolLayerV2Utils


static void labelTextToSld( QDomDocument &doc, QDomElement &element, QString label,
QFont font, QColor color = QColor(), double size = -1 );
const QFont& font, QColor color = QColor(), double size = -1 );

/** Create ogr feature style string for pen */
static QString ogrFeatureStylePen( double width, double mmScaleFactor, double mapUnitsScaleFactor, const QColor& c,
Expand Down
2 changes: 1 addition & 1 deletion python/core/symbology-ng/qgssymbolv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class QgsSymbolV2
* @note added in QGIS 2.9
* @see setClipFeaturesToExtent
*/
double clipFeaturesToExtent() const;
bool clipFeaturesToExtent() const;

QSet<QString> usedAttributes() const;

Expand Down
1 change: 1 addition & 0 deletions src/analysis/raster/qgsrelief.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ QList< QgsRelief::ReliefColor > QgsRelief::calculateOptimizedReliefClasses()
colorList.push_back( QColor( 255, 133, 92 ) );
colorList.push_back( QColor( 204, 204, 204 ) );

resultList.reserve( classBreaks.size() );
for ( int i = 1; i < classBreaks.size(); ++i )
{
double minElevation = minMax[0] + classBreaks[i - 1] * frequencyClassRange;
Expand Down
1 change: 1 addition & 0 deletions src/analysis/vector/qgstransectsample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ QgsGeometry* QgsTransectSample::clipBufferLine( const QgsGeometry* stratumGeom,
}

int size = bufferPolygon.size();
mpl.reserve( size );
for ( int j = 0; j < size; ++j )
{
mpl.append( bufferPolygon[j] );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsattributetabledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ void QgsAttributeTableDialog::columnBoxInit()

QList<QgsField> fields = mLayer->fields().toList();

Q_FOREACH ( const QgsField field, fields )
Q_FOREACH ( const QgsField& field, fields )
{
int idx = mLayer->fieldNameIndex( field.name() );
if ( idx < 0 )
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsconfigureshortcutsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void QgsConfigureShortcutsDialog::populateActions()
QList<QAction*> actions = QgsShortcutsManager::instance()->listActions();

QList<QTreeWidgetItem *> items;
items.reserve( actions.count() );
for ( int i = 0; i < actions.count(); ++i )
{
QString actionText = actions[i]->text();
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsdiagramproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,9 @@ void QgsDiagramProperties::apply()
QList<QColor> categoryColors;
QList<QString> categoryAttributes;
QList<QString> categoryLabels;
categoryColors.reserve( mDiagramAttributesTreeWidget->topLevelItemCount() );
categoryAttributes.reserve( mDiagramAttributesTreeWidget->topLevelItemCount() );
categoryLabels.reserve( mDiagramAttributesTreeWidget->topLevelItemCount() );
for ( int i = 0; i < mDiagramAttributesTreeWidget->topLevelItemCount(); ++i )
{
QColor color = mDiagramAttributesTreeWidget->topLevelItem( i )->background( 1 ).color();
Expand Down
1 change: 1 addition & 0 deletions src/app/qgslabeldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void QgsLabelDialog::init()
const QgsFields& myFields = mLabel->fields();
QStringList myFieldStringList;
myFieldStringList.append( "" );
myFieldStringList.reserve( 1 + myFields.count() );
for ( int i = 0; i < myFields.count(); ++i )
{
myFieldStringList.append( myFields[i].name() );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptooladdfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
QgsCurveV2* curveToAdd = 0;
if ( hasCurvedSegments && providerSupportsCurvedSegments )
{
curveToAdd = dynamic_cast<QgsCurveV2*>( captureCurve()->clone() );
curveToAdd = captureCurve()->clone();
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptooladdpart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void QgsMapToolAddPart::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
QgsCurveV2* curveToAdd = 0;
if ( hasCurvedSegments && providerSupportsCurvedSegments )
{
curveToAdd = dynamic_cast<QgsCurveV2*>( captureCurve()->clone() );
curveToAdd = captureCurve()->clone();
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptooladdring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void QgsMapToolAddRing::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
QgsCurveV2* curveToAdd = 0;
if ( hasCurvedSegments && providerSupportsCurvedSegments )
{
curveToAdd = dynamic_cast<QgsCurveV2*>( captureCurve()->clone() );
curveToAdd = captureCurve()->clone();
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsmergeattributesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ QVariant QgsMergeAttributesDialog::sumAttribute( int col )
QVariant QgsMergeAttributesDialog::concatenationAttribute( int col )
{
QStringList concatString;
concatString.reserve( mFeatureList.size() );
for ( int i = 0; i < mFeatureList.size(); ++i )
{
concatString << mTableWidget->item( i + 1, col )->text();
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1911,6 +1911,7 @@ void QgsOptions::on_pbnExportScales_clicked()
}

QStringList myScales;
myScales.reserve( mListGlobalScales->count() );
for ( int i = 0; i < mListGlobalScales->count(); ++i )
{
myScales.append( mListGlobalScales->item( i )->text() );
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsprojectproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ void QgsProjectProperties::apply()

//save project scales
QStringList myScales;
myScales.reserve( lstScales->count() );
for ( int i = 0; i < lstScales->count(); ++i )
{
myScales.append( lstScales->item( i )->text() );
Expand Down
11 changes: 6 additions & 5 deletions src/core/auth/qgsauthcertutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ QString QgsAuthCertUtils::getSslProtocolName( QSsl::SslProtocol protocol )
QMap<QString, QSslCertificate> QgsAuthCertUtils::mapDigestToCerts( QList<QSslCertificate> certs )
{
QMap<QString, QSslCertificate> digestmap;
Q_FOREACH ( QSslCertificate cert, certs )
Q_FOREACH ( const QSslCertificate& cert, certs )
{
digestmap.insert( shaHexForCert( cert ), cert );
}
Expand All @@ -59,7 +59,7 @@ QMap<QString, QSslCertificate> QgsAuthCertUtils::mapDigestToCerts( QList<QSslCer
QMap<QString, QList<QSslCertificate> > QgsAuthCertUtils::certsGroupedByOrg( QList<QSslCertificate> certs )
{
QMap< QString, QList<QSslCertificate> > orgcerts;
Q_FOREACH ( QSslCertificate cert, certs )
Q_FOREACH ( const QSslCertificate& cert, certs )
{
QString org( cert.subjectInfo( QSslCertificate::Organization ) );
if ( org.isEmpty() )
Expand All @@ -73,7 +73,7 @@ QMap<QString, QList<QSslCertificate> > QgsAuthCertUtils::certsGroupedByOrg( QLis
QMap<QString, QgsAuthConfigSslServer> QgsAuthCertUtils::mapDigestToSslConfigs( QList<QgsAuthConfigSslServer> configs )
{
QMap<QString, QgsAuthConfigSslServer> digestmap;
Q_FOREACH ( QgsAuthConfigSslServer config, configs )
Q_FOREACH ( const QgsAuthConfigSslServer& config, configs )
{
digestmap.insert( shaHexForCert( config.sslCertificate() ), config );
}
Expand All @@ -83,7 +83,7 @@ QMap<QString, QgsAuthConfigSslServer> QgsAuthCertUtils::mapDigestToSslConfigs( Q
QMap<QString, QList<QgsAuthConfigSslServer> > QgsAuthCertUtils::sslConfigsGroupedByOrg( QList<QgsAuthConfigSslServer> configs )
{
QMap< QString, QList<QgsAuthConfigSslServer> > orgconfigs;
Q_FOREACH ( QgsAuthConfigSslServer config, configs )
Q_FOREACH ( const QgsAuthConfigSslServer& config, configs )
{
QString org( config.sslCertificate().subjectInfo( QSslCertificate::Organization ) );
if ( org.isEmpty() )
Expand Down Expand Up @@ -371,6 +371,7 @@ QString QgsAuthCertUtils::getColonDelimited( const QString &txt )
// 64321c05b0ebab8e2b67ec0d7d9e2b6d4bc3c303
// -> 64:32:1c:05:b0:eb:ab:8e:2b:67:ec:0d:7d:9e:2b:6d:4b:c3:c3:03
QStringList sl;
sl.reserve( txt.size() );
for ( int i = 0; i < txt.size(); i += 2 )
{
sl << txt.mid( i, ( i + 2 > txt.size() ) ? -1 : 2 );
Expand Down Expand Up @@ -593,7 +594,7 @@ QList<QgsAuthCertUtils::CertUsageType> QgsAuthCertUtils::certificateUsageTypes(
}

QList<QCA::ConstraintType> certconsts = qcacert.constraints();
Q_FOREACH ( QCA::ConstraintType certconst, certconsts )
Q_FOREACH ( const QCA::ConstraintType& certconst, certconsts )
{
if ( certconst.known() == QCA::KeyCertificateSign )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/auth/qgsauthconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ const QgsPkiBundle QgsPkiBundle::fromPkcs12Paths( const QString &bundlepath,
if ( cert_chain.size() > 1 )
{
QList<QSslCertificate> ca_chain;
Q_FOREACH ( QCA::Certificate ca_cert, cert_chain )
Q_FOREACH ( const QCA::Certificate& ca_cert, cert_chain )
{
if ( ca_cert != cert_chain.primary() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/auth/qgsauthmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2328,7 +2328,7 @@ const QList<QSslCertificate> QgsAuthManager::getExtraFileCAs()
filecerts = QgsAuthCertUtils::certsFromFile( cafile );
}
// only CAs or certs capable of signing other certs are allowed
Q_FOREACH ( QSslCertificate cert, filecerts )
Q_FOREACH ( const QSslCertificate& cert, filecerts )
{
if ( !allowinvalid.toBool() && !cert.isValid() )
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/composer/qgscomposerlegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ QString QgsComposerLegend::wrapChar() const {return mSettings.wrapChar(); }
int QgsComposerLegend::columnCount() const { return mSettings.columnCount(); }
void QgsComposerLegend::setColumnCount( int c ) { mSettings.setColumnCount( c ); }

int QgsComposerLegend::splitLayer() const { return mSettings.splitLayer(); }
bool QgsComposerLegend::splitLayer() const { return mSettings.splitLayer(); }
void QgsComposerLegend::setSplitLayer( bool s ) { mSettings.setSplitLayer( s ); }

int QgsComposerLegend::equalColumnWidth() const { return mSettings.equalColumnWidth(); }
bool QgsComposerLegend::equalColumnWidth() const { return mSettings.equalColumnWidth(); }
void QgsComposerLegend::setEqualColumnWidth( bool s ) { mSettings.setEqualColumnWidth( s ); }


Expand Down
4 changes: 2 additions & 2 deletions src/core/composer/qgscomposerlegend.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
int columnCount() const;
void setColumnCount( int c );

int splitLayer() const;
bool splitLayer() const;
void setSplitLayer( bool s );

int equalColumnWidth() const;
bool equalColumnWidth() const;
void setEqualColumnWidth( bool s );

void setComposerMap( const QgsComposerMap* map );
Expand Down
1 change: 1 addition & 0 deletions src/core/composer/qgscomposermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,7 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
{
QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName( "Layer" );
layerSet.reserve( layerIdNodeList.size() );
for ( int i = 0; i < layerIdNodeList.size(); ++i )
{
const QDomElement& layerIdElement = layerIdNodeList.at( i ).toElement();
Expand Down
2 changes: 1 addition & 1 deletion src/core/dxf/qgsdxfexport.cpp
Original file line number Diff line number Diff line change