From 3cc57040d5c9673a0ababe4205ab1e87de7fa6e1 Mon Sep 17 00:00:00 2001 From: mhugent Date: Sat, 13 Oct 2007 09:03:38 +0000 Subject: [PATCH] Avoid two geometry copies in postgresprovider. Just pass geometry pointers instead git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7270 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/core/qgsfeature.cpp | 5 +++++ src/core/qgsfeature.h | 3 +++ src/providers/postgres/qgspostgresprovider.cpp | 12 ++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/core/qgsfeature.cpp b/src/core/qgsfeature.cpp index fd4974e89df9..8273f62b52c8 100644 --- a/src/core/qgsfeature.cpp +++ b/src/core/qgsfeature.cpp @@ -171,6 +171,11 @@ const QgsAttributeMap& QgsFeature::attributeMap() const return mAttributes; } +void QgsFeature::setAttributeMap(const QgsAttributeMap& attributeMap) +{ + mAttributes = attributeMap; +} + /** * Add an attribute to the map */ diff --git a/src/core/qgsfeature.h b/src/core/qgsfeature.h index 8d5a97432c05..937d8e035bf7 100644 --- a/src/core/qgsfeature.h +++ b/src/core/qgsfeature.h @@ -101,6 +101,9 @@ class CORE_EXPORT QgsFeature { */ const QgsAttributeMap& attributeMap() const; + /**Sets all the attributes in one go*/ + void setAttributeMap(const QgsAttributeMap& attributeMap); + /** * Add an attribute to the map */ diff --git a/src/providers/postgres/qgspostgresprovider.cpp b/src/providers/postgres/qgspostgresprovider.cpp index 4fb00596623e..60b0c1a54748 100644 --- a/src/providers/postgres/qgspostgresprovider.cpp +++ b/src/providers/postgres/qgspostgresprovider.cpp @@ -476,7 +476,11 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature) } } - mFeatureQueue.push(feature); + //don't copy the geometry. Just pass a pointer instead + mFeatureQueue.push(QgsFeature()); + mFeatureQueue.back().setGeometry(feature.geometryAndOwnership()); + mFeatureQueue.back().setFeatureId(feature.featureId()); + mFeatureQueue.back().setAttributeMap(feature.attributeMap()); } // for each row in queue @@ -490,7 +494,11 @@ bool QgsPostgresProvider::getNextFeature(QgsFeature& feature) } // if new queue is required // Now return the next feature from the queue - feature = mFeatureQueue.front(); + //don't copy the geometry. Just pass a pointer instead + feature.setGeometry(mFeatureQueue.front().geometryAndOwnership()); + feature.setFeatureId(mFeatureQueue.front().featureId()); + feature.setAttributeMap(mFeatureQueue.front().attributeMap()); + mFeatureQueue.pop(); }