Skip to content
Permalink
Browse files

[memory] Optimise iteration, avoid multiple map lookups and an unnece…

…ssary expression evaluation

(cherry picked from commit 51a4981)
  • Loading branch information
nyalldawson committed Feb 12, 2019
1 parent 197625d commit 082ebd07fc97e5ce935b77861e284fa252fd2c26
Showing with 7 additions and 5 deletions.
  1. +7 −5 src/core/providers/memory/qgsmemoryfeatureiterator.cpp
@@ -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 )
@@ -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;
}
@@ -149,7 +151,7 @@ bool QgsMemoryFeatureIterator::nextFeatureUsingList( QgsFeature &feature )
// copy feature
if ( hasFeature )
{
feature = mSource->mFeatures.value( *mFeatureIdListIterator );
feature = candidate;
++mFeatureIdListIterator;
}
else

0 comments on commit 082ebd0

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