Skip to content
Permalink
Browse files

Optimize QgsVectorLayerFeatureIterator a bit

11% speedup when rendering 1 million points from memory provider
  • Loading branch information
wonder-sk committed Oct 3, 2014
1 parent ebae485 commit 86015ea429da1941128b0ba8f185205996d30061
Showing with 18 additions and 7 deletions.
  1. +16 −7 src/core/qgsvectorlayerfeatureiterator.cpp
  2. +2 −0 src/core/qgsvectorlayerfeatureiterator.h
@@ -96,6 +96,8 @@ QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayerFeat

prepareExpressions();

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

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

@@ -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
@@ -311,7 +315,8 @@ void QgsVectorLayerFeatureIterator::useAddedFeature( const QgsFeature& src, QgsF

f.setAttributes( src.attributes() );

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


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

updateChangedAttributes( f );

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

if ( mRequest.filterType() == QgsFeatureRequest::FilterExpression )
{
@@ -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() );
}
}
@@ -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;
}
@@ -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;

0 comments on commit 86015ea

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