Skip to content

Commit 86015ea

Browse files
committed
Optimize QgsVectorLayerFeatureIterator a bit
11% speedup when rendering 1 million points from memory provider
1 parent ebae485 commit 86015ea

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/core/qgsvectorlayerfeatureiterator.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayerFeat
9696

9797
prepareExpressions();
9898

99+
mHasVirtualAttributes = !mFetchJoinInfo.isEmpty() || !mExpressionFieldInfo.isEmpty();
100+
99101
// by default provider's request is the same
100102
mProviderRequest = mRequest;
101103

@@ -211,9 +213,11 @@ bool QgsVectorLayerFeatureIterator::fetchFeature( QgsFeature& f )
211213
f.setFields( &mSource->mFields );
212214

213215
// update attributes
214-
updateChangedAttributes( f );
216+
if ( mSource->mHasEditBuffer )
217+
updateChangedAttributes( f );
215218

216-
addVirtualAttributes( f );
219+
if ( mHasVirtualAttributes )
220+
addVirtualAttributes( f );
217221

218222
// update geometry
219223
// TODO[MK]: FilterRect check after updating the geometry
@@ -311,7 +315,8 @@ void QgsVectorLayerFeatureIterator::useAddedFeature( const QgsFeature& src, QgsF
311315

312316
f.setAttributes( src.attributes() );
313317

314-
addVirtualAttributes( f );
318+
if ( mHasVirtualAttributes )
319+
addVirtualAttributes( f );
315320
}
316321

317322

@@ -351,7 +356,8 @@ bool QgsVectorLayerFeatureIterator::fetchNextChangedAttributeFeature( QgsFeature
351356

352357
updateChangedAttributes( f );
353358

354-
addVirtualAttributes( f );
359+
if ( mHasVirtualAttributes )
360+
addVirtualAttributes( f );
355361

356362
if ( mRequest.filterType() == QgsFeatureRequest::FilterExpression )
357363
{
@@ -404,7 +410,8 @@ void QgsVectorLayerFeatureIterator::useChangedAttributeFeature( QgsFeatureId fid
404410
QgsFeatureIterator fi = mSource->mProviderFeatureSource->getFeatures( request );
405411
if ( fi.nextFeature( tmp ) )
406412
{
407-
updateChangedAttributes( tmp );
413+
if ( mHasVirtualAttributes )
414+
updateChangedAttributes( tmp );
408415
f.setAttributes( tmp.attributes() );
409416
}
410417
}
@@ -732,9 +739,11 @@ bool QgsVectorLayerFeatureIterator::nextFeatureFid( QgsFeature& f )
732739
QgsFeatureIterator fi = mSource->mProviderFeatureSource->getFeatures( mProviderRequest );
733740
if ( fi.nextFeature( f ) )
734741
{
735-
updateChangedAttributes( f );
742+
if ( mSource->mHasEditBuffer )
743+
updateChangedAttributes( f );
736744

737-
addVirtualAttributes( f );
745+
if ( mHasVirtualAttributes )
746+
addVirtualAttributes( f );
738747

739748
return true;
740749
}

src/core/qgsvectorlayerfeatureiterator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureItera
152152

153153
QMap<int, QgsExpression*> mExpressionFieldInfo;
154154

155+
bool mHasVirtualAttributes;
156+
155157
private:
156158
//! optional object to locally simplify edited (changed or added) geometries fetched by this feature iterator
157159
QgsAbstractGeometrySimplifier* mEditGeometrySimplifier;

0 commit comments

Comments
 (0)