Skip to content

Commit fe4278d

Browse files
author
mhugent
committed
Avoid two geometry copies in postgresprovider. Just pass geometry pointers instead
git-svn-id: http://svn.osgeo.org/qgis/trunk@7270 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e47e592 commit fe4278d

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/core/qgsfeature.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ const QgsAttributeMap& QgsFeature::attributeMap() const
171171
return mAttributes;
172172
}
173173

174+
void QgsFeature::setAttributeMap(const QgsAttributeMap& attributeMap)
175+
{
176+
mAttributes = attributeMap;
177+
}
178+
174179
/**
175180
* Add an attribute to the map
176181
*/

src/core/qgsfeature.h

+3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class CORE_EXPORT QgsFeature {
101101
*/
102102
const QgsAttributeMap& attributeMap() const;
103103

104+
/**Sets all the attributes in one go*/
105+
void setAttributeMap(const QgsAttributeMap& attributeMap);
106+
104107
/**
105108
* Add an attribute to the map
106109
*/

src/providers/postgres/qgspostgresprovider.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,11 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)
476476
}
477477
}
478478

479-
mFeatureQueue.push(feature);
479+
//don't copy the geometry. Just pass a pointer instead
480+
mFeatureQueue.push(QgsFeature());
481+
mFeatureQueue.back().setGeometry(feature.geometryAndOwnership());
482+
mFeatureQueue.back().setFeatureId(feature.featureId());
483+
mFeatureQueue.back().setAttributeMap(feature.attributeMap());
480484

481485
} // for each row in queue
482486

@@ -490,7 +494,11 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature)
490494
} // if new queue is required
491495

492496
// Now return the next feature from the queue
493-
feature = mFeatureQueue.front();
497+
//don't copy the geometry. Just pass a pointer instead
498+
feature.setGeometry(mFeatureQueue.front().geometryAndOwnership());
499+
feature.setFeatureId(mFeatureQueue.front().featureId());
500+
feature.setAttributeMap(mFeatureQueue.front().attributeMap());
501+
494502
mFeatureQueue.pop();
495503

496504
}

0 commit comments

Comments
 (0)