Skip to content

Commit

Permalink
Micro optimization: very slightly cheaper QgsFeature::initAttributes …
Browse files Browse the repository at this point in the history
…call
  • Loading branch information
nyalldawson committed Sep 28, 2018
1 parent 8ae35de commit 94b1082
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/core/qgsfeature.cpp
Expand Up @@ -195,10 +195,10 @@ bool QgsFeature::hasGeometry() const
void QgsFeature::initAttributes( int fieldCount )
{
d.detach();
d->attributes.resize( 0 ); // clears existing elements, while still preserving the currently allocated capacity of the list (unlike clear)
// ensures ALL attributes, including previously existing ones are default constructed.
// doing it this way also avoids clearing individual QVariants -- which can trigger a detachment. Cheaper just to make a new one.
d->attributes.resize( fieldCount );
QVariant *ptr = d->attributes.data();
for ( int i = 0; i < fieldCount; ++i, ++ptr )
ptr->clear();
}

bool QgsFeature::setAttribute( int idx, const QVariant &value )
Expand Down

0 comments on commit 94b1082

Please sign in to comment.