Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Avoid calling canDriverShareSameDatasetAmongLayers for every ogr feat…
…ure processed, call once upfront
  • Loading branch information
nyalldawson committed May 9, 2023
1 parent c870269 commit 4c4ccb9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/core/providers/ogr/qgsogrfeatureiterator.cpp
Expand Up @@ -327,7 +327,7 @@ bool QgsOgrFeatureIterator::fetchFeatureWithId( QgsFeatureId id, QgsFeature &fea
feature.setValid( false );
gdal::ogr_feature_unique_ptr fet;

if ( mAllowResetReading && !QgsOgrProviderUtils::canDriverShareSameDatasetAmongLayers( mSource->mDriverName ) )
if ( mAllowResetReading && !mSource->mCanDriverShareSameDatasetAmongLayers )
{
OGRLayerH nextFeatureBelongingLayer;
bool found = false;
Expand Down Expand Up @@ -465,7 +465,7 @@ bool QgsOgrFeatureIterator::fetchFeature( QgsFeature &feature )

// OSM layers (especially large ones) need the GDALDataset::GetNextFeature() call rather than OGRLayer::GetNextFeature()
// see more details here: https://trac.osgeo.org/gdal/wiki/rfc66_randomlayerreadwrite
if ( !QgsOgrProviderUtils::canDriverShareSameDatasetAmongLayers( mSource->mDriverName ) )
if ( !mSource->mCanDriverShareSameDatasetAmongLayers )
{
OGRLayerH nextFeatureBelongingLayer;
while ( fet.reset( GDALDatasetGetNextFeature( mConn->ds, &nextFeatureBelongingLayer, nullptr, nullptr, nullptr ) ), fet )
Expand Down Expand Up @@ -498,7 +498,7 @@ void QgsOgrFeatureIterator::resetReading()
{
return;
}
if ( !QgsOgrProviderUtils::canDriverShareSameDatasetAmongLayers( mSource->mDriverName ) )
if ( !mSource->mCanDriverShareSameDatasetAmongLayers )
{
GDALDatasetResetReading( mConn->ds );
}
Expand Down Expand Up @@ -702,6 +702,8 @@ QgsOgrFeatureSource::QgsOgrFeatureSource( const QgsOgrProvider *p )
for ( int i = ( p->mFirstFieldIsFid ) ? 1 : 0; i < mFields.size(); i++ )
mFieldsWithoutFid.append( mFields.at( i ) );
QgsOgrConnPool::instance()->ref( QgsOgrProviderUtils::connectionPoolId( mDataSource, mShareSameDatasetAmongLayers ) );

mCanDriverShareSameDatasetAmongLayers = QgsOgrProviderUtils::canDriverShareSameDatasetAmongLayers( mDriverName );
}

QgsOgrFeatureSource::~QgsOgrFeatureSource()
Expand Down
1 change: 1 addition & 0 deletions src/core/providers/ogr/qgsogrfeatureiterator.h
Expand Up @@ -63,6 +63,7 @@ class QgsOgrFeatureSource final: public QgsAbstractFeatureSource
Qgis::WkbType mWkbType = Qgis::WkbType::Unknown;
QgsOgrDatasetSharedPtr mSharedDS = nullptr;
QgsTransaction *mTransaction = nullptr;
bool mCanDriverShareSameDatasetAmongLayers = true;

friend class QgsOgrFeatureIterator;
friend class QgsOgrExpressionCompiler;
Expand Down

0 comments on commit 4c4ccb9

Please sign in to comment.