Skip to content

Commit

Permalink
[memory] Optimise iteration, avoid multiple map lookups and an unnece…
Browse files Browse the repository at this point in the history
…ssary expression evaluation

(cherry picked from commit 51a4981)
  • Loading branch information
nyalldawson committed Feb 12, 2019
1 parent 197625d commit 082ebd0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/core/providers/memory/qgsmemoryfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,16 @@ bool QgsMemoryFeatureIterator::nextFeatureUsingList( QgsFeature &feature )
bool hasFeature = false;

// option 1: we have a list of features to traverse
QgsFeature candidate;
while ( mFeatureIdListIterator != mFeatureIdList.constEnd() )
{
candidate = mSource->mFeatures.value( *mFeatureIdListIterator );
if ( !mFilterRect.isNull() )
{
if ( mRequest.flags() & QgsFeatureRequest::ExactIntersect )
{
// do exact check in case we're doing intersection
if ( mSource->mFeatures.value( *mFeatureIdListIterator ).hasGeometry() && mSelectRectEngine->intersects( mSource->mFeatures.value( *mFeatureIdListIterator ).geometry().constGet() ) )
if ( candidate.hasGeometry() && mSelectRectEngine->intersects( candidate.geometry().constGet() ) )
hasFeature = true;
}
else if ( mSource->mSpatialIndex )
Expand All @@ -126,16 +128,16 @@ bool QgsMemoryFeatureIterator::nextFeatureUsingList( QgsFeature &feature )
else
{
// do bounding box check if we aren't using a spatial index
if ( mSource->mFeatures.value( *mFeatureIdListIterator ).hasGeometry() && mSource->mFeatures.value( *mFeatureIdListIterator ).geometry().boundingBoxIntersects( mFilterRect ) )
if ( candidate.hasGeometry() && candidate.geometry().boundingBoxIntersects( mFilterRect ) )
hasFeature = true;
}
}
else
hasFeature = true;

if ( mSubsetExpression )
if ( hasFeature && mSubsetExpression )
{
mSource->mExpressionContext.setFeature( mSource->mFeatures.value( *mFeatureIdListIterator ) );
mSource->mExpressionContext.setFeature( candidate );
if ( !mSubsetExpression->evaluate( &mSource->mExpressionContext ).toBool() )
hasFeature = false;
}
Expand All @@ -149,7 +151,7 @@ bool QgsMemoryFeatureIterator::nextFeatureUsingList( QgsFeature &feature )
// copy feature
if ( hasFeature )
{
feature = mSource->mFeatures.value( *mFeatureIdListIterator );
feature = candidate;
++mFeatureIdListIterator;
}
else
Expand Down

0 comments on commit 082ebd0

Please sign in to comment.