[geos-commits] r2922 - in trunk: capi
include/geos/operation/polygonize src/operation/polygonize
svn_geos at osgeo.org
svn_geos at osgeo.org
Mon Feb 22 16:41:15 EST 2010
Author: strk
Date: 2010-02-22 16:41:13 -0500 (Mon, 22 Feb 2010)
New Revision: 2922
Modified:
trunk/capi/geos_ts_c.cpp
trunk/include/geos/operation/polygonize/PolygonizeEdge.h
trunk/include/geos/operation/polygonize/Polygonizer.h
trunk/src/operation/polygonize/Polygonizer.cpp
Log:
Avoid heap allocation of a vector for cut edges, bits of additional documentation
Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp 2010-02-22 21:29:55 UTC (rev 2921)
+++ trunk/capi/geos_ts_c.cpp 2010-02-22 21:41:13 UTC (rev 2922)
@@ -2429,8 +2429,7 @@
handle->NOTICE_MESSAGE("geometry vector added to polygonizer");
#endif
- std::vector<const LineString *>* lines = plgnzr.getCutEdges();
- assert(0 != lines);
+ const std::vector<const LineString *>& lines = plgnzr.getCutEdges();
#if GEOS_DEBUG
handle->NOTICE_MESSAGE("output polygons got");
@@ -2441,13 +2440,12 @@
// nature, so we explicitly convert.
// (it's just a waste of processor and memory, btw)
// XXX mloskot: See comment for GEOSPolygonize_r
- std::vector<Geometry*> *linevec = new std::vector<Geometry *>(lines->size());
+ std::vector<Geometry*> *linevec = new std::vector<Geometry *>(lines.size());
- for (std::size_t i = 0; i < lines->size(); ++i)
+ for (std::size_t i = 0, n=lines.size(); i < n; ++i)
{
- (*linevec)[i] = (*lines)[i]->clone();
+ (*linevec)[i] = lines[i]->clone();
}
- // FIXME mloskot: Who deallocates vector pointed by lines* ?
const GeometryFactory *gf = handle->geomFactory;
Modified: trunk/include/geos/operation/polygonize/PolygonizeEdge.h
===================================================================
--- trunk/include/geos/operation/polygonize/PolygonizeEdge.h 2010-02-22 21:29:55 UTC (rev 2921)
+++ trunk/include/geos/operation/polygonize/PolygonizeEdge.h 2010-02-22 21:41:13 UTC (rev 2922)
@@ -44,9 +44,14 @@
*/
class GEOS_DLL PolygonizeEdge: public planargraph::Edge {
private:
+ // Externally owned
const geom::LineString *line;
public:
+
+ // Keep the given pointer (won't do anything to it)
PolygonizeEdge(const geom::LineString *newLine);
+
+ // Just return what it was given initially
const geom::LineString* getLine();
};
Modified: trunk/include/geos/operation/polygonize/Polygonizer.h
===================================================================
--- trunk/include/geos/operation/polygonize/Polygonizer.h 2010-02-22 21:29:55 UTC (rev 2921)
+++ trunk/include/geos/operation/polygonize/Polygonizer.h 2010-02-22 21:41:13 UTC (rev 2922)
@@ -114,7 +114,7 @@
// initialize with empty collections, in case nothing is computed
std::vector<const geom::LineString*> *dangles;
- std::vector<const geom::LineString*> *cutEdges;
+ std::vector<const geom::LineString*> cutEdges;
std::vector<geom::LineString*> *invalidRingLines;
std::vector<EdgeRing*> *holeList;
@@ -202,7 +202,7 @@
*
* TODO: return by const vector reference instead !
*/
- std::vector<const geom::LineString*>* getCutEdges();
+ const std::vector<const geom::LineString*>& getCutEdges();
/** \brief
* Get the list of lines forming invalid rings found during
Modified: trunk/src/operation/polygonize/Polygonizer.cpp
===================================================================
--- trunk/src/operation/polygonize/Polygonizer.cpp 2010-02-22 21:29:55 UTC (rev 2921)
+++ trunk/src/operation/polygonize/Polygonizer.cpp 2010-02-22 21:41:13 UTC (rev 2922)
@@ -63,7 +63,7 @@
lineStringAdder(new Polygonizer::LineStringAdder(this)),
graph(NULL),
dangles(NULL),
- cutEdges(NULL),
+ cutEdges(),
invalidRingLines(NULL),
holeList(NULL),
shellList(NULL),
@@ -75,7 +75,6 @@
{
delete lineStringAdder;
delete dangles;
- delete cutEdges;
delete graph;
delete holeList;
@@ -200,7 +199,7 @@
* Get the list of cut edges found during polygonization.
* @return a collection of the input {@LineStrings} which are cut edges
*/
-vector<const LineString*>*
+const vector<const LineString*>&
Polygonizer::getCutEdges()
{
polygonize();
@@ -238,9 +237,7 @@
dangles = new std::vector<const LineString*>();
graph->deleteDangles(*dangles);
- // TODO: drop this heap allocation
- cutEdges = new std::vector<const LineString*>();
- graph->deleteCutEdges(*cutEdges);
+ graph->deleteCutEdges(cutEdges);
vector<EdgeRing*> edgeRingList;
graph->getEdgeRings(edgeRingList);
More information about the geos-commits
mailing list