Skip to content

Commit

Permalink
Optimize QgsVectorLayerFeatureIterator a bit
Browse files Browse the repository at this point in the history
11% speedup when rendering 1 million points from memory provider
  • Loading branch information
wonder-sk committed Oct 3, 2014
1 parent ebae485 commit 86015ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/core/qgsvectorlayerfeatureiterator.cpp
Expand Up @@ -96,6 +96,8 @@ QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayerFeat

prepareExpressions();

mHasVirtualAttributes = !mFetchJoinInfo.isEmpty() || !mExpressionFieldInfo.isEmpty();

// by default provider's request is the same
mProviderRequest = mRequest;

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

// update attributes
updateChangedAttributes( f );
if ( mSource->mHasEditBuffer )
updateChangedAttributes( f );

addVirtualAttributes( f );
if ( mHasVirtualAttributes )
addVirtualAttributes( f );

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

f.setAttributes( src.attributes() );

addVirtualAttributes( f );
if ( mHasVirtualAttributes )
addVirtualAttributes( f );
}


Expand Down Expand Up @@ -351,7 +356,8 @@ bool QgsVectorLayerFeatureIterator::fetchNextChangedAttributeFeature( QgsFeature

updateChangedAttributes( f );

addVirtualAttributes( f );
if ( mHasVirtualAttributes )
addVirtualAttributes( f );

if ( mRequest.filterType() == QgsFeatureRequest::FilterExpression )
{
Expand Down Expand Up @@ -404,7 +410,8 @@ void QgsVectorLayerFeatureIterator::useChangedAttributeFeature( QgsFeatureId fid
QgsFeatureIterator fi = mSource->mProviderFeatureSource->getFeatures( request );
if ( fi.nextFeature( tmp ) )
{
updateChangedAttributes( tmp );
if ( mHasVirtualAttributes )
updateChangedAttributes( tmp );
f.setAttributes( tmp.attributes() );
}
}
Expand Down Expand Up @@ -732,9 +739,11 @@ bool QgsVectorLayerFeatureIterator::nextFeatureFid( QgsFeature& f )
QgsFeatureIterator fi = mSource->mProviderFeatureSource->getFeatures( mProviderRequest );
if ( fi.nextFeature( f ) )
{
updateChangedAttributes( f );
if ( mSource->mHasEditBuffer )
updateChangedAttributes( f );

addVirtualAttributes( f );
if ( mHasVirtualAttributes )
addVirtualAttributes( f );

return true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsvectorlayerfeatureiterator.h
Expand Up @@ -152,6 +152,8 @@ class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureItera

QMap<int, QgsExpression*> mExpressionFieldInfo;

bool mHasVirtualAttributes;

private:
//! optional object to locally simplify edited (changed or added) geometries fetched by this feature iterator
QgsAbstractGeometrySimplifier* mEditGeometrySimplifier;
Expand Down

0 comments on commit 86015ea

Please sign in to comment.