[geos-commits] [SCM] GEOS branch master updated. 2fbaf5707f11ed364bceddfd1960b8be3c28bdc5
git at osgeo.org
git at osgeo.org
Sun Sep 15 12:00:50 PDT 2019
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".
The branch, master has been updated
via 2fbaf5707f11ed364bceddfd1960b8be3c28bdc5 (commit)
from 9b821a1759771181c177a1902721618d5f7bb042 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 2fbaf5707f11ed364bceddfd1960b8be3c28bdc5
Author: Daniel Baston <dbaston at gmail.com>
Date: Sun Sep 15 15:00:38 2019 -0400
Simplify MakeValid
Remove some unneeded heap allocation and copying between std::vectors of
Geometry and its subclasses.
diff --git a/src/operation/valid/MakeValid.cpp b/src/operation/valid/MakeValid.cpp
index 90f9b62..a85eb41 100644
--- a/src/operation/valid/MakeValid.cpp
+++ b/src/operation/valid/MakeValid.cpp
@@ -92,7 +92,6 @@ static std::unique_ptr<geom::Geometry> MakeValidLine(const geom::LineString* lin
static std::unique_ptr<geom::Geometry> MakeValidMultiLine(const geom::MultiLineString* mls)
{
-
std::vector<std::unique_ptr<geom::Geometry>> points;
std::vector<std::unique_ptr<geom::Geometry>> lines;
@@ -122,13 +121,7 @@ static std::unique_ptr<geom::Geometry> MakeValidMultiLine(const geom::MultiLineS
std::unique_ptr<geom::Geometry> pointsRet;
if( !points.empty() ) {
if( points.size() > 1 ) {
- auto pointsRawPtr = new std::vector<geom::Geometry*>(points.size());
- for( size_t i = 0; i < points.size(); i++ ) {
- auto pointMoved = std::move(points[i]);
- (*pointsRawPtr)[i] = pointMoved.release();
- }
- pointsRet.reset(
- mls->getFactory()->createMultiPoint(pointsRawPtr));
+ pointsRet = mls->getFactory()->createMultiPoint(std::move(points));
} else {
pointsRet = std::move(points[0]);
}
@@ -137,24 +130,17 @@ static std::unique_ptr<geom::Geometry> MakeValidMultiLine(const geom::MultiLineS
std::unique_ptr<geom::Geometry> linesRet;
if( !lines.empty() ) {
if( lines.size() > 1 ) {
- auto linesRawPtr = new std::vector<geom::Geometry*>(lines.size());
- for( size_t i = 0; i < lines.size(); i++ ) {
- auto lineMoved = std::move(lines[i]);
- (*linesRawPtr)[i] = lineMoved.release();
- }
- linesRet.reset(
- mls->getFactory()->createMultiLineString(linesRawPtr));
+ linesRet = mls->getFactory()->createMultiLineString(std::move(lines));
} else {
linesRet = std::move(lines[0]);
}
}
if( pointsRet && linesRet ) {
- auto geoms = new std::vector<geom::Geometry*>(2);
- (*geoms)[0] = pointsRet.release();
- (*geoms)[1] = linesRet.release();
- return std::unique_ptr<geom::Geometry>(
- mls->getFactory()->createGeometryCollection(geoms));
+ std::vector<std::unique_ptr<Geometry>> geoms(2);
+ geoms[0] = std::move(pointsRet);
+ geoms[1] = std::move(linesRet);
+ return mls->getFactory()->createGeometryCollection(std::move(geoms));
} else if( pointsRet ) {
return pointsRet;
} else if( linesRet ) {
@@ -175,18 +161,15 @@ static std::unique_ptr<geom::Geometry> extractUniquePoints(const geom::Geometry*
geom->apply_ro(&filter);
/* 2: for each point, create a geometry and put into a vector */
- auto points = new std::vector<geom::Geometry*>();
- points->reserve(coords.size());
+ std::vector<std::unique_ptr<Geometry>> points;
+ points.reserve(coords.size());
const GeometryFactory* factory = geom->getFactory();
- for(std::vector<const geom::Coordinate*>::iterator it = coords.begin(),
- itE = coords.end();
- it != itE; ++it) {
- auto point = factory->createPoint(*(*it));
- points->push_back(point);
+ for(const Coordinate* c : coords) {
+ points.emplace_back(factory->createPoint(*c));
}
/* 3: create a multipoint */
- return std::unique_ptr<geom::Geometry>(factory->createMultiPoint(points));
+ return factory->createMultiPoint(std::move(points));
}
static std::unique_ptr<geom::Geometry> MakeValidPoly(const geom::Geometry* geom)
@@ -260,50 +243,36 @@ static std::unique_ptr<geom::Geometry> MakeValidPoly(const geom::Geometry* geom)
cut_edges = std::move(new_cut_edges);
}
- auto vgeoms = new std::vector<Geometry*>(3);
+ std::vector<std::unique_ptr<Geometry>> vgeoms(3);
unsigned int nvgeoms=0;
if( !area->isEmpty() ) {
- (*vgeoms)[nvgeoms++] = area.release();
+ vgeoms[nvgeoms++] = std::move(area);
}
if( !cut_edges->isEmpty() ) {
- (*vgeoms)[nvgeoms++] = cut_edges.release();
+ vgeoms[nvgeoms++] = std::move(cut_edges);
}
if( !collapse_points->isEmpty() ) {
- (*vgeoms)[nvgeoms++] = collapse_points.release();
+ vgeoms[nvgeoms++] = std::move(collapse_points);
}
if( nvgeoms == 1 ) {
/* Return cut edges */
- auto ret = std::unique_ptr<geom::Geometry>((*vgeoms)[0]);
- delete vgeoms;
- return ret;
+ return std::move(vgeoms[0]);
}
/* Collect areas and lines (if any line) */
- vgeoms->resize(nvgeoms);
- return std::unique_ptr<geom::Geometry>(
- factory->createGeometryCollection(vgeoms));
+ vgeoms.resize(nvgeoms);
+ return factory->createGeometryCollection(std::move(vgeoms));
}
static std::unique_ptr<geom::Geometry> MakeValidCollection(const geom::GeometryCollection* coll)
{
- auto validGeoms = new std::vector<geom::Geometry*>();
- try {
- for(const auto& geom: *coll )
- {
- validGeoms->push_back(MakeValid().build(geom.get()).release());
- }
- return std::unique_ptr<geom::Geometry>(
- GeometryFactory::create()->createGeometryCollection(validGeoms));
- }
- catch( ... ) {
- for( auto geom: *validGeoms ) {
- delete geom;
- }
- delete validGeoms;
- throw;
+ std::vector<std::unique_ptr<Geometry>> validGeoms;
+ for(const auto& geom: *coll) {
+ validGeoms.push_back(MakeValid().build(geom.get()));
}
+ return coll->getFactory()->createGeometryCollection(std::move(validGeoms));
}
/** Return a valid version of the input geometry. */
-----------------------------------------------------------------------
Summary of changes:
src/operation/valid/MakeValid.cpp | 75 ++++++++++++---------------------------
1 file changed, 22 insertions(+), 53 deletions(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list