Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0c1f4f6

Browse files
authoredJun 18, 2021
Revert "Fix massive performance regression in attribute table"
This reverts commit 5fdb88b.
1 parent d17f591 commit 0c1f4f6

File tree

4 files changed

+8
-31
lines changed

4 files changed

+8
-31
lines changed
 

‎python/core/auto_generated/vector/qgsvectorlayercache.sip.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313

14+
1415
class QgsVectorLayerCache : QObject
1516
{
1617
%Docstring(signature="appended")

‎src/core/qgscachedfeatureiterator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ QgsCachedFeatureIterator::QgsCachedFeatureIterator( QgsVectorLayerCache *vlCache
5353
break;
5454

5555
default:
56-
mFeatureIds = QList( mVectorLayerCache->mCacheOrderedKeys.begin(), mVectorLayerCache->mCacheOrderedKeys.end() );
56+
mFeatureIds = mVectorLayerCache->mCacheOrderedKeys;
5757
break;
5858
}
5959

‎src/core/vector/qgsvectorlayercache.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,7 @@ bool QgsVectorLayerCache::removeCachedFeature( QgsFeatureId fid )
177177
{
178178
bool removed = mCache.remove( fid );
179179
if ( removed )
180-
{
181-
if ( auto unorderedIt = std::find( mCacheUnorderedKeys.begin(), mCacheUnorderedKeys.end(), fid ); unorderedIt != mCacheUnorderedKeys.end() )
182-
{
183-
mCacheUnorderedKeys.erase( unorderedIt );
184-
185-
if ( auto orderedIt = std::find( mCacheOrderedKeys.begin(), mCacheOrderedKeys.end(), fid ); orderedIt != mCacheOrderedKeys.end() )
186-
mCacheOrderedKeys.erase( orderedIt );
187-
}
188-
}
180+
mCacheOrderedKeys.removeOne( fid );
189181
return removed;
190182
}
191183

@@ -278,13 +270,7 @@ void QgsVectorLayerCache::onJoinAttributeValueChanged( QgsFeatureId fid, int fie
278270
void QgsVectorLayerCache::featureDeleted( QgsFeatureId fid )
279271
{
280272
mCache.remove( fid );
281-
282-
if ( auto it = mCacheUnorderedKeys.find( fid ); it != mCacheUnorderedKeys.end() )
283-
{
284-
mCacheUnorderedKeys.erase( it );
285-
if ( auto orderedIt = std::find( mCacheOrderedKeys.begin(), mCacheOrderedKeys.end(), fid ); orderedIt != mCacheOrderedKeys.end() )
286-
mCacheOrderedKeys.erase( orderedIt );
287-
}
273+
mCacheOrderedKeys.removeOne( fid );
288274
}
289275

290276
void QgsVectorLayerCache::onFeatureAdded( QgsFeatureId fid )
@@ -344,7 +330,6 @@ void QgsVectorLayerCache::invalidate()
344330
{
345331
mCache.clear();
346332
mCacheOrderedKeys.clear();
347-
mCacheUnorderedKeys.clear();
348333
mFullCache = false;
349334
emit invalidated();
350335
}

‎src/core/vector/qgsvectorlayercache.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
#include "qgsfield.h"
2525
#include "qgsfeaturerequest.h"
2626
#include "qgsfeatureiterator.h"
27-
#include <unordered_set>
28-
#include <deque>
27+
2928
#include <QCache>
3029

3130
class QgsVectorLayer;
@@ -394,21 +393,13 @@ class CORE_EXPORT QgsVectorLayerCache : public QObject
394393
{
395394
QgsCachedFeature *cachedFeature = new QgsCachedFeature( feat, this );
396395
mCache.insert( feat.id(), cachedFeature );
397-
if ( mCacheUnorderedKeys.find( feat.id() ) == mCacheUnorderedKeys.end() )
398-
{
399-
mCacheUnorderedKeys.insert( feat.id() );
400-
mCacheOrderedKeys.emplace_back( feat.id() );
401-
}
396+
if ( !mCacheOrderedKeys.contains( feat.id() ) )
397+
mCacheOrderedKeys << feat.id();
402398
}
403399

404400
QgsVectorLayer *mLayer = nullptr;
405401
QCache< QgsFeatureId, QgsCachedFeature > mCache;
406-
407-
// we need two containers here. One is used for efficient tracking of the IDs which have been added to the cache, the other
408-
// is used to store the order of the incoming feature ids, so that we can correctly iterate through features in the original order.
409-
// 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
410-
std::unordered_set< QgsFeatureId > mCacheUnorderedKeys;
411-
std::deque< QgsFeatureId > mCacheOrderedKeys;
402+
QList< QgsFeatureId > mCacheOrderedKeys;
412403

413404
bool mCacheGeometry = true;
414405
bool mFullCache = false;

0 commit comments

Comments
 (0)
Please sign in to comment.