Skip to content
Permalink
Browse files
Revert "Fix massive performance regression in attribute table"
This reverts commit 5fdb88b.
  • Loading branch information
3nids committed Jun 18, 2021
1 parent d17f591 commit 0c1f4f6c8d1c00fa42167784b0aa38ffc5cc6ece
@@ -11,6 +11,7 @@




class QgsVectorLayerCache : QObject
{
%Docstring(signature="appended")
@@ -53,7 +53,7 @@ QgsCachedFeatureIterator::QgsCachedFeatureIterator( QgsVectorLayerCache *vlCache
break;

default:
mFeatureIds = QList( mVectorLayerCache->mCacheOrderedKeys.begin(), mVectorLayerCache->mCacheOrderedKeys.end() );
mFeatureIds = mVectorLayerCache->mCacheOrderedKeys;
break;
}

@@ -177,15 +177,7 @@ bool QgsVectorLayerCache::removeCachedFeature( QgsFeatureId fid )
{
bool removed = mCache.remove( fid );
if ( removed )
{
if ( auto unorderedIt = std::find( mCacheUnorderedKeys.begin(), mCacheUnorderedKeys.end(), fid ); unorderedIt != mCacheUnorderedKeys.end() )
{
mCacheUnorderedKeys.erase( unorderedIt );

if ( auto orderedIt = std::find( mCacheOrderedKeys.begin(), mCacheOrderedKeys.end(), fid ); orderedIt != mCacheOrderedKeys.end() )
mCacheOrderedKeys.erase( orderedIt );
}
}
mCacheOrderedKeys.removeOne( fid );
return removed;
}

@@ -278,13 +270,7 @@ void QgsVectorLayerCache::onJoinAttributeValueChanged( QgsFeatureId fid, int fie
void QgsVectorLayerCache::featureDeleted( QgsFeatureId fid )
{
mCache.remove( fid );

if ( auto it = mCacheUnorderedKeys.find( fid ); it != mCacheUnorderedKeys.end() )
{
mCacheUnorderedKeys.erase( it );
if ( auto orderedIt = std::find( mCacheOrderedKeys.begin(), mCacheOrderedKeys.end(), fid ); orderedIt != mCacheOrderedKeys.end() )
mCacheOrderedKeys.erase( orderedIt );
}
mCacheOrderedKeys.removeOne( fid );
}

void QgsVectorLayerCache::onFeatureAdded( QgsFeatureId fid )
@@ -344,7 +330,6 @@ void QgsVectorLayerCache::invalidate()
{
mCache.clear();
mCacheOrderedKeys.clear();
mCacheUnorderedKeys.clear();
mFullCache = false;
emit invalidated();
}
@@ -24,8 +24,7 @@
#include "qgsfield.h"
#include "qgsfeaturerequest.h"
#include "qgsfeatureiterator.h"
#include <unordered_set>
#include <deque>

#include <QCache>

class QgsVectorLayer;
@@ -394,21 +393,13 @@ class CORE_EXPORT QgsVectorLayerCache : public QObject
{
QgsCachedFeature *cachedFeature = new QgsCachedFeature( feat, this );
mCache.insert( feat.id(), cachedFeature );
if ( mCacheUnorderedKeys.find( feat.id() ) == mCacheUnorderedKeys.end() )
{
mCacheUnorderedKeys.insert( feat.id() );
mCacheOrderedKeys.emplace_back( feat.id() );
}
if ( !mCacheOrderedKeys.contains( feat.id() ) )
mCacheOrderedKeys << feat.id();
}

QgsVectorLayer *mLayer = nullptr;
QCache< QgsFeatureId, QgsCachedFeature > mCache;

// we need two containers here. One is used for efficient tracking of the IDs which have been added to the cache, the other
// is used to store the order of the incoming feature ids, so that we can correctly iterate through features in the original order.
// the ordered list alone is far too slow to handle this -- searching for existing items in a list is magnitudes slower than the unordered_set
std::unordered_set< QgsFeatureId > mCacheUnorderedKeys;
std::deque< QgsFeatureId > mCacheOrderedKeys;
QList< QgsFeatureId > mCacheOrderedKeys;

bool mCacheGeometry = true;
bool mFullCache = false;

0 comments on commit 0c1f4f6

Please sign in to comment.