[geos-commits] r2733 - in trunk/source: headers/geos/planargraph operation/linemerge operation/polygonize planargraph

svn_geos at osgeo.org svn_geos at osgeo.org
Fri Nov 20 14:58:35 EST 2009


Author: strk
Date: 2009-11-20 14:58:33 -0500 (Fri, 20 Nov 2009)
New Revision: 2733

Modified:
   trunk/source/headers/geos/planargraph/NodeMap.h
   trunk/source/headers/geos/planargraph/PlanarGraph.h
   trunk/source/operation/linemerge/LineMerger.cpp
   trunk/source/operation/polygonize/PolygonizeGraph.cpp
   trunk/source/planargraph/NodeMap.cpp
Log:
Don't force heap allocation of vectors for getting nodes of a NodeMap 


Modified: trunk/source/headers/geos/planargraph/NodeMap.h
===================================================================
--- trunk/source/headers/geos/planargraph/NodeMap.h	2009-11-19 21:30:01 UTC (rev 2732)
+++ trunk/source/headers/geos/planargraph/NodeMap.h	2009-11-20 19:58:33 UTC (rev 2733)
@@ -106,8 +106,10 @@
 	 * \brief
 	 * Returns the Nodes in this NodeMap, sorted in ascending order
 	 * by angle with the positive x-axis.
+	 *
+	 * @param nodes : the nodes are push_back'ed here
 	 */
-	std::vector<Node*>* getNodes();
+	void getNodes(std::vector<Node*>& nodes);
 };
 
 

Modified: trunk/source/headers/geos/planargraph/PlanarGraph.h
===================================================================
--- trunk/source/headers/geos/planargraph/PlanarGraph.h	2009-11-19 21:30:01 UTC (rev 2732)
+++ trunk/source/headers/geos/planargraph/PlanarGraph.h	2009-11-20 19:58:33 UTC (rev 2733)
@@ -142,8 +142,10 @@
 	/**
 	 * \brief
 	 * Returns the Nodes in this PlanarGraph.
+	 *
+	 * @param nodes : the nodes are push_back'ed here
 	 */  
-	std::vector<Node*>* getNodes() { return nodeMap.getNodes(); }
+	void getNodes(std::vector<Node*>& nodes) { nodeMap.getNodes(nodes); }
 
 	/**
 	 * \brief

Modified: trunk/source/operation/linemerge/LineMerger.cpp
===================================================================
--- trunk/source/operation/linemerge/LineMerger.cpp	2009-11-19 21:30:01 UTC (rev 2732)
+++ trunk/source/operation/linemerge/LineMerger.cpp	2009-11-20 19:58:33 UTC (rev 2733)
@@ -143,9 +143,12 @@
 #if GEOS_DEBUG
 	cerr<<__FUNCTION__<<endl;
 #endif
-	vector<Node*> *nodes=graph.getNodes();
-	for (size_t i=0; i<nodes->size(); ++i) {
-		Node *node=(*nodes)[i];
+	typedef std::vector<Node*> Nodes;
+
+	Nodes nodes;
+	graph.getNodes(nodes);
+	for (Nodes::size_type i=0, in=nodes.size(); i<in; ++i) {
+		Node *node=nodes[i];
 #if GEOS_DEBUG
 		cerr<<"Node "<<i<<": "<<*node<<endl;
 #endif
@@ -158,7 +161,6 @@
 #endif
 		}
 	}
-	delete nodes;
 }
 
 void
@@ -167,10 +169,12 @@
 #if GEOS_DEBUG
 	cerr<<__FUNCTION__<<endl;
 #endif
-	vector<Node*> *nodes=graph.getNodes();
-	size_t size=nodes->size();
-	for (size_t i=0; i<size; i++) {
-		Node *node=(*nodes)[i];
+	typedef std::vector<Node*> Nodes;
+
+	Nodes nodes;
+	graph.getNodes(nodes);
+	for (Nodes::size_type i=0, in=nodes.size(); i<in; ++i) {
+		Node *node=nodes[i];
 #if GEOS_DEBUG
 		cerr<<"Node "<<i<<": "<<*node<<endl;
 #endif
@@ -182,7 +186,6 @@
 #endif
 		}
 	}
-	delete nodes;
 }
 
 void

Modified: trunk/source/operation/polygonize/PolygonizeGraph.cpp
===================================================================
--- trunk/source/operation/polygonize/PolygonizeGraph.cpp	2009-11-19 21:30:01 UTC (rev 2732)
+++ trunk/source/operation/polygonize/PolygonizeGraph.cpp	2009-11-20 19:58:33 UTC (rev 2733)
@@ -162,13 +162,13 @@
 void
 PolygonizeGraph::computeNextCWEdges()
 {
-	std::vector<Node*> *pns=getNodes();
+	typedef std::vector<Node*> Nodes;
+	Nodes pns; getNodes(pns);
 	// set the next pointers for the edges around each node
-	for(int i=0;i<(int)pns->size();i++) {
-		Node *node=(*pns)[i];
+	for(Nodes::size_type i=0, in=pns.size(); i<in; ++i) {
+		Node *node=pns[i];
 		computeNextCWEdges(node);
 	}
-	delete pns;
 }
 
 /* private */

Modified: trunk/source/planargraph/NodeMap.cpp
===================================================================
--- trunk/source/planargraph/NodeMap.cpp	2009-11-19 21:30:01 UTC (rev 2732)
+++ trunk/source/planargraph/NodeMap.cpp	2009-11-20 19:58:33 UTC (rev 2733)
@@ -64,16 +64,15 @@
 	return n;
 }
 
-vector<Node*>*
-NodeMap::getNodes()
+/* public */
+void
+NodeMap::getNodes(vector<Node*>& values)
 {
-	vector<Node*> *values=new vector<Node*>();
-	NodeMap::container::iterator it=nodeMap.begin();
-	while(it!=nodeMap.end()) {
-		values->push_back(it->second);
+	NodeMap::container::iterator it=nodeMap.begin(), itE=nodeMap.end();
+	while (it != itE) {
+		values.push_back(it->second);
 		++it;
 	}
-	return values;
 }
 
 /**



More information about the geos-commits mailing list