[geos-commits] [SCM] GEOS branch master updated. 84ba018a9f88e1118ab9d05d3b42bc383a4176f0

git at osgeo.org git at osgeo.org
Tue Jun 18 07:01:57 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  84ba018a9f88e1118ab9d05d3b42bc383a4176f0 (commit)
       via  b7dd304e54341a78815394b2a465852d3658c89c (commit)
       via  2e503e6c434961a1fff3a6ebe46d6fbfbf325911 (commit)
       via  9b7a1db25859f6f5a77b61ebee2bab0163d16b4c (commit)
      from  a64c3d737ae771d9734a987c5620dee6720a87df (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 84ba018a9f88e1118ab9d05d3b42bc383a4176f0
Merge: a64c3d7 b7dd304
Author: Daniel Baston <dbaston at gmail.com>
Date:   Tue Jun 18 10:01:38 2019 -0400

    Merge branch 'geometryeditor-uniqueptr'


commit b7dd304e54341a78815394b2a465852d3658c89c
Author: Daniel Baston <dbaston at gmail.com>
Date:   Mon Jun 17 21:09:09 2019 -0400

    Return unique_ptr from GeometryCombiner

diff --git a/include/geos/geom/util/GeometryCombiner.h b/include/geos/geom/util/GeometryCombiner.h
index 8fcf5be..c40ea22 100644
--- a/include/geos/geom/util/GeometryCombiner.h
+++ b/include/geos/geom/util/GeometryCombiner.h
@@ -19,6 +19,7 @@
 #ifndef GEOS_GEOM_UTIL_GEOMETRYCOMBINER_H
 #define GEOS_GEOM_UTIL_GEOMETRYCOMBINER_H
 
+#include <memory>
 #include <vector>
 
 // Forward declarations
@@ -52,7 +53,7 @@ public:
      * @param geoms the geometries to combine (ownership left to caller)
      * @return the combined geometry
      */
-    static Geometry* combine(std::vector<Geometry*> const& geoms);
+    static std::unique_ptr<Geometry> combine(std::vector<Geometry*> const& geoms);
 
     /**
      * Combines two geometries.
@@ -61,7 +62,7 @@ public:
      * @param g1 a geometry to combine (ownership left to caller)
      * @return the combined geometry
      */
-    static Geometry* combine(const Geometry* g0, const Geometry* g1);
+    static std::unique_ptr<Geometry> combine(const Geometry* g0, const Geometry* g1);
 
     /**
      * Combines three geometries.
@@ -71,7 +72,7 @@ public:
      * @param g2 a geometry to combine (ownership left to caller)
      * @return the combined geometry
      */
-    static Geometry* combine(const Geometry* g0, const Geometry* g1, const Geometry* g2);
+    static std::unique_ptr<Geometry> combine(const Geometry* g0, const Geometry* g1, const Geometry* g2);
 
 private:
     GeometryFactory const* geomFactory;
@@ -100,7 +101,7 @@ public:
      *
      * @return a Geometry which is the combination of the inputs
      */
-    Geometry* combine();
+    std::unique_ptr<Geometry> combine();
 
 private:
     void extractElements(Geometry* geom, std::vector<Geometry*>& elems);
diff --git a/src/geom/util/GeometryCombiner.cpp b/src/geom/util/GeometryCombiner.cpp
index 5580b92..f174c51 100644
--- a/src/geom/util/GeometryCombiner.cpp
+++ b/src/geom/util/GeometryCombiner.cpp
@@ -25,14 +25,14 @@ namespace geos {
 namespace geom { // geos.geom
 namespace util { // geos.geom.util
 
-Geometry*
+std::unique_ptr<Geometry>
 GeometryCombiner::combine(std::vector<Geometry*> const& geoms)
 {
     GeometryCombiner combiner(geoms);
     return combiner.combine();
 }
 
-Geometry*
+std::unique_ptr<Geometry>
 GeometryCombiner::combine(const Geometry* g0, const Geometry* g1)
 {
     std::vector<Geometry*> geoms;
@@ -43,7 +43,7 @@ GeometryCombiner::combine(const Geometry* g0, const Geometry* g1)
     return combiner.combine();
 }
 
-Geometry*
+std::unique_ptr<Geometry>
 GeometryCombiner::combine(const Geometry* g0, const Geometry* g1,
                           const Geometry* g2)
 {
@@ -67,26 +67,24 @@ GeometryCombiner::extractFactory(std::vector<Geometry*> const& geoms)
     return geoms.empty() ? nullptr : geoms.front()->getFactory();
 }
 
-Geometry*
+std::unique_ptr<Geometry>
 GeometryCombiner::combine()
 {
     std::vector<Geometry*> elems;
 
-    std::vector<Geometry*>::const_iterator end = inputGeoms.end();
-    for(std::vector<Geometry*>::const_iterator i = inputGeoms.begin();
-            i != end; ++i) {
-        extractElements(*i, elems);
+    for(const auto& geom : inputGeoms) {
+        extractElements(geom, elems);
     }
 
     if(elems.empty()) {
         if(geomFactory != nullptr) {
-            return geomFactory->createGeometryCollection(nullptr);
+            return std::unique_ptr<Geometry>(geomFactory->createGeometryCollection(nullptr));
         }
         return nullptr;
     }
 
     // return the "simplest possible" geometry
-    return geomFactory->buildGeometry(elems);
+    return std::unique_ptr<Geometry>(geomFactory->buildGeometry(elems));
 }
 
 void
diff --git a/src/operation/union/CascadedPolygonUnion.cpp b/src/operation/union/CascadedPolygonUnion.cpp
index 6134684..ff6fdef 100644
--- a/src/operation/union/CascadedPolygonUnion.cpp
+++ b/src/operation/union/CascadedPolygonUnion.cpp
@@ -241,7 +241,7 @@ CascadedPolygonUnion::unionOptimized(geom::Geometry* g0, geom::Geometry* g1)
     geom::Envelope const* g1Env = g1->getEnvelopeInternal();
 
     if(!g0Env->intersects(g1Env)) {
-        return geom::util::GeometryCombiner::combine(g0, g1);
+        return geom::util::GeometryCombiner::combine(g0, g1).release();
     }
 
     if(g0->getNumGeometries() <= 1 && g1->getNumGeometries() <= 1) {
@@ -318,13 +318,13 @@ CascadedPolygonUnion::unionUsingEnvelopeIntersection(geom::Geometry* g0,
     std::unique_ptr<geom::Geometry> ret;
     if(polysOn.empty()) {
         disjointPolys.push_back(u.get());
-        ret.reset(geom::util::GeometryCombiner::combine(disjointPolys));
+        ret = geom::util::GeometryCombiner::combine(disjointPolys);
     }
     else {
         // TODO: could be further tweaked to only union with polysOn
         //       and combine with polysOff, but then it'll need again to
         //       recurse in the check for disjoint/intersecting
-        ret.reset(geom::util::GeometryCombiner::combine(disjointPolys));
+        ret = geom::util::GeometryCombiner::combine(disjointPolys);
         ret.reset(unionActual(ret.get(), u.get()));
     }
 
diff --git a/src/operation/union/CascadedUnion.cpp b/src/operation/union/CascadedUnion.cpp
index 2dbc52c..8d7a96f 100644
--- a/src/operation/union/CascadedUnion.cpp
+++ b/src/operation/union/CascadedUnion.cpp
@@ -152,7 +152,7 @@ CascadedUnion::unionOptimized(geom::Geometry* g0, geom::Geometry* g1)
     geom::Envelope const* g1Env = g1->getEnvelopeInternal();
 
     if(!g0Env->intersects(g1Env)) {
-        return geom::util::GeometryCombiner::combine(g0, g1);
+        return geom::util::GeometryCombiner::combine(g0, g1).release();
     }
 
     if(g0->getNumGeometries() <= 1 && g1->getNumGeometries() <= 1) {
@@ -176,7 +176,7 @@ CascadedUnion::unionUsingEnvelopeIntersection(geom::Geometry* g0,
     std::unique_ptr<geom::Geometry> u(unionActual(g0Int.get(), g1Int.get()));
     disjointPolys.push_back(u.get());
 
-    return geom::util::GeometryCombiner::combine(disjointPolys);
+    return geom::util::GeometryCombiner::combine(disjointPolys).release();
 }
 
 geom::Geometry*
diff --git a/src/precision/PrecisionReducerCoordinateOperation.cpp b/src/precision/PrecisionReducerCoordinateOperation.cpp
index 69affc1..91649df 100644
--- a/src/precision/PrecisionReducerCoordinateOperation.cpp
+++ b/src/precision/PrecisionReducerCoordinateOperation.cpp
@@ -57,7 +57,7 @@ PrecisionReducerCoordinateOperation::edit(const CoordinateSequence* cs,
 
     // remove repeated points, to simplify returned geometry as
     // much as possible.
-    auto noRepeatedCoords = operation::valid::RepeatedPointRemover::removeRepeatedPoints(reducedCoords.get());
+    std::unique_ptr<CoordinateSequence> noRepeatedCoords = operation::valid::RepeatedPointRemover::removeRepeatedPoints(reducedCoords.get());
 
     /**
      * Check to see if the removal of repeated points
diff --git a/src/precision/SimpleGeometryPrecisionReducer.cpp b/src/precision/SimpleGeometryPrecisionReducer.cpp
index bd99dd3..54e82ac 100644
--- a/src/precision/SimpleGeometryPrecisionReducer.cpp
+++ b/src/precision/SimpleGeometryPrecisionReducer.cpp
@@ -87,7 +87,7 @@ PrecisionReducerCoordinateOperation::edit(const CoordinateSequence* cs,
 
     // remove repeated points, to simplify returned geometry as
     // much as possible.
-    auto noRepeatedCoords = operation::valid::RepeatedPointRemover::removeRepeatedPoints(reducedCoords.get());
+    std::unique_ptr<CoordinateSequence> noRepeatedCoords = operation::valid::RepeatedPointRemover::removeRepeatedPoints(reducedCoords.get());
 
     /**
      * Check to see if the removal of repeated points

commit 2e503e6c434961a1fff3a6ebe46d6fbfbf325911
Author: Daniel Baston <dbaston at gmail.com>
Date:   Mon Jun 17 13:13:00 2019 -0400

    Use unique_ptr in GeometryEditor

diff --git a/include/geos/geom/util/CoordinateOperation.h b/include/geos/geom/util/CoordinateOperation.h
index 8f5701f..2c79cf4 100644
--- a/include/geos/geom/util/CoordinateOperation.h
+++ b/include/geos/geom/util/CoordinateOperation.h
@@ -45,8 +45,8 @@ public:
     /**
      * Return a newly created geometry, ownership to caller
      */
-    Geometry* edit(const Geometry* geometry,
-                   const GeometryFactory* factory) override;
+    std::unique_ptr<Geometry> edit(const Geometry* geometry,
+                                   const GeometryFactory* factory) override;
 
     /**
      * Edits the array of Coordinate from a Geometry.
@@ -56,11 +56,11 @@ public:
      * @return an edited coordinate array (which may be the same as
      *         the input)
      */
-    virtual CoordinateSequence* edit(const CoordinateSequence* coordinates,
-                                     const Geometry* geometry) = 0;
+    virtual std::unique_ptr<CoordinateSequence> edit(const CoordinateSequence* coordinates,
+                                                     const Geometry* geometry) = 0;
 
 
-    ~CoordinateOperation() override {}
+    ~CoordinateOperation() override = default;
 };
 
 
diff --git a/include/geos/geom/util/GeometryEditor.h b/include/geos/geom/util/GeometryEditor.h
index 77cbaa8..229bc7d 100644
--- a/include/geos/geom/util/GeometryEditor.h
+++ b/include/geos/geom/util/GeometryEditor.h
@@ -22,6 +22,7 @@
 #define GEOS_GEOM_UTIL_GEOMETRYEDITOR_H
 
 #include <geos/export.h>
+#include <memory>
 
 // Forward declarations
 namespace geos {
@@ -82,12 +83,12 @@ private:
      */
     const GeometryFactory* factory;
 
-    Polygon* editPolygon(const Polygon* polygon,
-                         GeometryEditorOperation* operation);
+    std::unique_ptr<Polygon> editPolygon(const Polygon* polygon,
+                                         GeometryEditorOperation* operation);
 
-    GeometryCollection* editGeometryCollection(
-        const GeometryCollection* collection,
-        GeometryEditorOperation* operation);
+    std::unique_ptr<GeometryCollection> editGeometryCollection(
+            const GeometryCollection* collection,
+            GeometryEditorOperation* operation);
 
 public:
 
@@ -117,8 +118,8 @@ public:
      * @return a new Geometry which is the result of the editing
      *
      */
-    Geometry* edit(const Geometry* geometry,
-                   GeometryEditorOperation* operation); // final
+    std::unique_ptr<Geometry> edit(const Geometry* geometry,
+                                   GeometryEditorOperation* operation); // final
 };
 
 } // namespace geos.geom.util
diff --git a/include/geos/geom/util/GeometryEditorOperation.h b/include/geos/geom/util/GeometryEditorOperation.h
index 4824903..8757a7d 100644
--- a/include/geos/geom/util/GeometryEditorOperation.h
+++ b/include/geos/geom/util/GeometryEditorOperation.h
@@ -17,6 +17,7 @@
 #define GEOS_GEOM_UTIL_GEOMETRYEDITOROPERATION_H
 
 #include <geos/export.h>
+#include <memory>
 
 // Forward declarations
 namespace geos {
@@ -50,8 +51,8 @@ public:
      *
      * @return a new Geometry which is a modification of the input Geometry
      */
-    virtual Geometry* edit(const Geometry* geometry,
-                           const GeometryFactory* factory) = 0;
+    virtual std::unique_ptr<Geometry> edit(const Geometry* geometry,
+                                           const GeometryFactory* factory) = 0;
 
     virtual
     ~GeometryEditorOperation() {}
diff --git a/include/geos/precision/PrecisionReducerCoordinateOperation.h b/include/geos/precision/PrecisionReducerCoordinateOperation.h
index 195c502..83fe7ec 100644
--- a/include/geos/precision/PrecisionReducerCoordinateOperation.h
+++ b/include/geos/precision/PrecisionReducerCoordinateOperation.h
@@ -57,8 +57,8 @@ public:
     /// Ownership of returned CoordinateSequence to caller
     //
     /// virtual function
-    geom::CoordinateSequence* edit(const geom::CoordinateSequence* coordinates,
-                                   const geom::Geometry* geom) override;
+    std::unique_ptr<geom::CoordinateSequence> edit(const geom::CoordinateSequence* coordinates,
+                                                   const geom::Geometry* geom) override;
 };
 
 } // namespace geos.precision
diff --git a/include/geos/precision/SimpleGeometryPrecisionReducer.h b/include/geos/precision/SimpleGeometryPrecisionReducer.h
index cd8b1b3..e39a732 100644
--- a/include/geos/precision/SimpleGeometryPrecisionReducer.h
+++ b/include/geos/precision/SimpleGeometryPrecisionReducer.h
@@ -16,6 +16,7 @@
 #define GEOS_PRECISION_SIMPLEGEOMETRYPRECISIONREDUCER_H
 
 #include <geos/export.h>
+#include <memory>
 
 // Forward declarations
 namespace geos {
@@ -80,7 +81,7 @@ public:
     const geom::PrecisionModel* getPrecisionModel();
 
     bool getRemoveCollapsed();
-    geom::Geometry* reduce(const geom::Geometry* geom);
+    std::unique_ptr<geom::Geometry> reduce(const geom::Geometry* geom);
 };
 
 } // namespace geos.precision
diff --git a/src/geom/GeometryFactory.cpp b/src/geom/GeometryFactory.cpp
index e7f3d2d..bc8c430 100644
--- a/src/geom/GeometryFactory.cpp
+++ b/src/geom/GeometryFactory.cpp
@@ -67,11 +67,11 @@ public:
     gfCoordinateOperation(const CoordinateSequenceFactory* gsf)
         : _gsf(gsf)
     {}
-    CoordinateSequence*
+    std::unique_ptr<CoordinateSequence>
     edit(const CoordinateSequence* coordSeq,
          const Geometry*) override
     {
-        return _gsf->create(*coordSeq).release();
+        return _gsf->create(*coordSeq);
     }
 };
 
@@ -777,8 +777,7 @@ GeometryFactory::createGeometry(const Geometry* g) const
     //return g->clone();
     util::GeometryEditor editor(this);
     gfCoordinateOperation coordOp(coordinateListFactory);
-    Geometry* ret = editor.edit(g, &coordOp);
-    return ret;
+    return editor.edit(g, &coordOp).release();
 }
 
 /*public*/
diff --git a/src/geom/util/CoordinateOperation.cpp b/src/geom/util/CoordinateOperation.cpp
index 5a50d30..7676fb7 100644
--- a/src/geom/util/CoordinateOperation.cpp
+++ b/src/geom/util/CoordinateOperation.cpp
@@ -26,30 +26,28 @@ namespace geos {
 namespace geom { // geos.geom
 namespace util { // geos.geom.util
 
-Geometry*
+std::unique_ptr<Geometry>
 CoordinateOperation::edit(const Geometry* geometry,
                           const GeometryFactory* factory)
 {
-    const LinearRing* ring = dynamic_cast<const LinearRing*>(geometry);
-    if(ring) {
+    if(const LinearRing* ring = dynamic_cast<const LinearRing*>(geometry)) {
         const CoordinateSequence* coords = ring->getCoordinatesRO();
-        CoordinateSequence* newCoords = edit(coords, geometry);
+        auto newCoords = edit(coords, geometry);
         // LinearRing instance takes over ownership of newCoords instance
-        return factory->createLinearRing(newCoords);
+        return std::unique_ptr<Geometry>(factory->createLinearRing(newCoords.release()));
     }
-    const LineString* line = dynamic_cast<const LineString*>(geometry);
-    if(line) {
+    if(const LineString* line = dynamic_cast<const LineString*>(geometry)) {
         const CoordinateSequence* coords = line->getCoordinatesRO();
-        CoordinateSequence* newCoords = edit(coords, geometry);
-        return factory->createLineString(newCoords);
+        auto newCoords = edit(coords, geometry);
+        return std::unique_ptr<Geometry>(factory->createLineString(newCoords.release()));
     }
-    if(typeid(*geometry) == typeid(Point)) {
-        auto coords = geometry->getCoordinates();
-        CoordinateSequence* newCoords = edit(coords.get(), geometry);
-        return factory->createPoint(newCoords);
+    if(const Point* point = dynamic_cast<const Point*>(geometry)) {
+        auto coords = point->getCoordinatesRO();
+        auto newCoords = edit(coords, geometry);
+        return std::unique_ptr<Geometry>(factory->createPoint(newCoords.release()));
     }
 
-    return geometry->clone().release();
+    return geometry->clone();
 }
 
 
diff --git a/src/geom/util/GeometryEditor.cpp b/src/geom/util/GeometryEditor.cpp
index 320d9b5..940417d 100644
--- a/src/geom/util/GeometryEditor.cpp
+++ b/src/geom/util/GeometryEditor.cpp
@@ -32,13 +32,12 @@
 #include <geos/geom/GeometryCollection.h>
 #include <geos/geom/util/GeometryEditorOperation.h>
 #include <geos/util/UnsupportedOperationException.h>
+#include <geos/util.h>
 
 #include <vector>
 #include <cassert>
 #include <typeinfo>
 
-using namespace std;
-
 namespace geos {
 namespace geom { // geos.geom
 namespace util { // geos.geom.util
@@ -72,7 +71,7 @@ GeometryEditor::GeometryEditor(const GeometryFactory* newFactory)
  * @param operation the edit operation to carry out
  * @return a new {@link Geometry} which is the result of the editing
  */
-Geometry*
+std::unique_ptr<Geometry>
 GeometryEditor::edit(const Geometry* geometry, GeometryEditorOperation* operation)
 {
     // if client did not supply a GeometryFactory, use the one from the input Geometry
@@ -102,17 +101,16 @@ GeometryEditor::edit(const Geometry* geometry, GeometryEditorOperation* operatio
     return nullptr;
 }
 
-Polygon*
+std::unique_ptr<Polygon>
 GeometryEditor::editPolygon(const Polygon* polygon, GeometryEditorOperation* operation)
 {
-    Polygon* newPolygon = dynamic_cast<Polygon*>(
-                              operation->edit(polygon, factory)
-                          );
+    std::unique_ptr<Polygon> newPolygon(dynamic_cast<Polygon*>(
+                                                operation->edit(polygon, factory).release()
+                                        ));
     if(newPolygon->isEmpty()) {
         //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino]
         if(newPolygon->getFactory() != factory) {
-            Polygon* ret = factory->createPolygon(nullptr, nullptr);
-            delete newPolygon;
+            std::unique_ptr<Polygon> ret(factory->createPolygon(nullptr, nullptr));
             return ret;
         }
         else {
@@ -120,64 +118,56 @@ GeometryEditor::editPolygon(const Polygon* polygon, GeometryEditorOperation* ope
         }
     }
 
-    Geometry* editResult = edit(newPolygon->getExteriorRing(), operation);
+    std::unique_ptr<LinearRing> shell(dynamic_cast<LinearRing*>(
+            edit(newPolygon->getExteriorRing(), operation).release()));
 
-    LinearRing* shell = dynamic_cast<LinearRing*>(editResult);
     if(shell->isEmpty()) {
         //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino]
-        delete shell;
-        delete newPolygon;
-        return factory->createPolygon(nullptr, nullptr);
+        return std::unique_ptr<Polygon>(factory->createPolygon(nullptr, nullptr));
     }
 
-    vector<LinearRing*>* holes = new vector<LinearRing*>;
+    auto holes = detail::make_unique<std::vector<LinearRing*>>();
     for(size_t i = 0, n = newPolygon->getNumInteriorRing(); i < n; ++i) {
 
-        Geometry* hole_geom = edit(newPolygon->getInteriorRingN(i),
-                                   operation);
+        std::unique_ptr<LinearRing> hole(dynamic_cast<LinearRing*>(
+                edit(newPolygon->getInteriorRingN(i), operation).release()));
 
-        LinearRing* hole = dynamic_cast<LinearRing*>(hole_geom);
         assert(hole);
 
         if(hole->isEmpty()) {
             continue;
         }
-        holes->push_back(hole);
+        holes->push_back(hole.release());
     }
-    delete newPolygon;
-    return factory->createPolygon(shell, holes);
+
+    return std::unique_ptr<Polygon>(factory->createPolygon(shell.release(), holes.release()));
 }
 
-GeometryCollection*
+std::unique_ptr<GeometryCollection>
 GeometryEditor::editGeometryCollection(const GeometryCollection* collection, GeometryEditorOperation* operation)
 {
-    GeometryCollection* newCollection = dynamic_cast<GeometryCollection*>(operation->edit(collection, factory));
-    vector<Geometry*>* geometries = new vector<Geometry*>();
+    auto newCollection = operation->edit(collection, factory);
+    auto geometries = detail::make_unique<std::vector<Geometry*>>();
     for(std::size_t i = 0, n = newCollection->getNumGeometries(); i < n; i++) {
-        Geometry* geometry = edit(newCollection->getGeometryN(i),
+        auto geometry = edit(newCollection->getGeometryN(i),
                                   operation);
         if(geometry->isEmpty()) {
-            delete geometry;
             continue;
         }
-        geometries->push_back(geometry);
+        geometries->push_back(geometry.release());
     }
 
-    if(typeid(*newCollection) == typeid(MultiPoint)) {
-        delete newCollection;
-        return factory->createMultiPoint(geometries);
+    if(newCollection->getGeometryTypeId() == GEOS_MULTIPOINT) {
+        return std::unique_ptr<GeometryCollection>(factory->createMultiPoint(geometries.release()));
     }
-    else if(typeid(*newCollection) == typeid(MultiLineString)) {
-        delete newCollection;
-        return factory->createMultiLineString(geometries);
+    else if(newCollection->getGeometryTypeId() == GEOS_MULTILINESTRING) {
+        return std::unique_ptr<GeometryCollection>(factory->createMultiLineString(geometries.release()));
     }
-    else if(typeid(*newCollection) == typeid(MultiPolygon)) {
-        delete newCollection;
-        return factory->createMultiPolygon(geometries);
+    else if(newCollection->getGeometryTypeId() == GEOS_MULTIPOLYGON) {
+        return std::unique_ptr<GeometryCollection>(factory->createMultiPolygon(geometries.release()));
     }
     else {
-        delete newCollection;
-        return factory->createGeometryCollection(geometries);
+        return std::unique_ptr<GeometryCollection>(factory->createGeometryCollection(geometries.release()));
     }
 }
 
diff --git a/src/precision/PrecisionReducerCoordinateOperation.cpp b/src/precision/PrecisionReducerCoordinateOperation.cpp
index b907f6f..69affc1 100644
--- a/src/precision/PrecisionReducerCoordinateOperation.cpp
+++ b/src/precision/PrecisionReducerCoordinateOperation.cpp
@@ -25,16 +25,16 @@
 #include <geos/geom/LineString.h>
 #include <geos/geom/LinearRing.h>
 #include <geos/operation/valid/RepeatedPointRemover.h>
+#include <geos/util.h>
 
 #include <vector>
 
 using namespace geos::geom;
-using namespace std;
 
 namespace geos {
 namespace precision { // geos.precision
 
-CoordinateSequence*
+std::unique_ptr<CoordinateSequence>
 PrecisionReducerCoordinateOperation::edit(const CoordinateSequence* cs,
         const Geometry* geom)
 {
@@ -44,7 +44,7 @@ PrecisionReducerCoordinateOperation::edit(const CoordinateSequence* cs,
         return nullptr;
     }
 
-    vector<Coordinate>* vc = new vector<Coordinate>(csSize);
+    auto vc = detail::make_unique<std::vector<Coordinate>>(csSize);
 
     // copy coordinates and reduce
     for(size_t i = 0; i < csSize; ++i) {
@@ -53,12 +53,11 @@ PrecisionReducerCoordinateOperation::edit(const CoordinateSequence* cs,
     }
 
     // reducedCoords take ownership of 'vc'
-    CoordinateSequence* reducedCoords =
-        geom->getFactory()->getCoordinateSequenceFactory()->create(vc).release();
+    auto reducedCoords = geom->getFactory()->getCoordinateSequenceFactory()->create(vc.release());
 
     // remove repeated points, to simplify returned geometry as
     // much as possible.
-    auto noRepeatedCoords = operation::valid::RepeatedPointRemover::removeRepeatedPoints(reducedCoords);
+    auto noRepeatedCoords = operation::valid::RepeatedPointRemover::removeRepeatedPoints(reducedCoords.get());
 
     /**
      * Check to see if the removal of repeated points
@@ -79,21 +78,17 @@ PrecisionReducerCoordinateOperation::edit(const CoordinateSequence* cs,
         minLength = 4;
     }
 
-    CoordinateSequence* collapsedCoords = reducedCoords;
     if(removeCollapsed) {
-        delete reducedCoords;
         reducedCoords = nullptr;
-        collapsedCoords = nullptr;
     }
 
-    // return null or orginal length coordinate array
+    // return null or original length coordinate array
     if(noRepeatedCoords->getSize() < minLength) {
-        return collapsedCoords;
+        return reducedCoords;
     }
 
     // ok to return shorter coordinate array
-    delete reducedCoords;
-    return noRepeatedCoords.release();
+    return noRepeatedCoords;
 }
 
 
diff --git a/src/precision/SimpleGeometryPrecisionReducer.cpp b/src/precision/SimpleGeometryPrecisionReducer.cpp
index 9ab876a..bd99dd3 100644
--- a/src/precision/SimpleGeometryPrecisionReducer.cpp
+++ b/src/precision/SimpleGeometryPrecisionReducer.cpp
@@ -28,11 +28,11 @@
 #include <geos/geom/LineString.h>
 #include <geos/geom/LinearRing.h>
 #include <geos/operation/valid/RepeatedPointRemover.h>
+#include <geos/util.h>
 
 #include <vector>
 #include <typeinfo>
 
-using namespace std;
 using namespace geos::geom;
 using namespace geos::geom::util;
 
@@ -54,8 +54,8 @@ public:
         SimpleGeometryPrecisionReducer* newSgpr);
 
     /// Ownership of returned CoordinateSequence to caller
-    CoordinateSequence* edit(const CoordinateSequence* coordinates,
-                             const Geometry* geom) override;
+    std::unique_ptr<CoordinateSequence> edit(const CoordinateSequence* coordinates,
+                                             const Geometry* geom) override;
 };
 
 PrecisionReducerCoordinateOperation::PrecisionReducerCoordinateOperation(
@@ -64,7 +64,7 @@ PrecisionReducerCoordinateOperation::PrecisionReducerCoordinateOperation(
     sgpr = newSgpr;
 }
 
-CoordinateSequence*
+std::unique_ptr<CoordinateSequence>
 PrecisionReducerCoordinateOperation::edit(const CoordinateSequence* cs,
         const Geometry* geom)
 {
@@ -74,7 +74,7 @@ PrecisionReducerCoordinateOperation::edit(const CoordinateSequence* cs,
 
     auto csSize = cs->size();
 
-    vector<Coordinate>* vc = new vector<Coordinate>(csSize);
+    auto vc = detail::make_unique<std::vector<Coordinate>>(csSize);
 
     // copy coordinates and reduce
     for(unsigned int i = 0; i < csSize; ++i) {
@@ -83,12 +83,11 @@ PrecisionReducerCoordinateOperation::edit(const CoordinateSequence* cs,
     }
 
     // reducedCoords take ownership of 'vc'
-    CoordinateSequence* reducedCoords =
-        geom->getFactory()->getCoordinateSequenceFactory()->create(vc).release();
+    auto reducedCoords = geom->getFactory()->getCoordinateSequenceFactory()->create(vc.release());
 
     // remove repeated points, to simplify returned geometry as
     // much as possible.
-    auto noRepeatedCoords = operation::valid::RepeatedPointRemover::removeRepeatedPoints(reducedCoords);
+    auto noRepeatedCoords = operation::valid::RepeatedPointRemover::removeRepeatedPoints(reducedCoords.get());
 
     /**
      * Check to see if the removal of repeated points
@@ -108,19 +107,16 @@ PrecisionReducerCoordinateOperation::edit(const CoordinateSequence* cs,
     if(typeid(*geom) == typeid(LinearRing)) {
         minLength = 4;
     }
-    CoordinateSequence* collapsedCoords = reducedCoords;
+
     if(sgpr->getRemoveCollapsed()) {
-        delete reducedCoords;
         reducedCoords = nullptr;
-        collapsedCoords = nullptr;
     }
-    // return null or orginal length coordinate array
+    // return null or original length coordinate array
     if(noRepeatedCoords->getSize() < minLength) {
-        return collapsedCoords;
+        return reducedCoords;
     }
     // ok to return shorter coordinate array
-    delete reducedCoords;
-    return noRepeatedCoords.release();
+    return noRepeatedCoords;
 }
 
 } // anonymous namespace
@@ -164,13 +160,12 @@ SimpleGeometryPrecisionReducer::getRemoveCollapsed()
     return removeCollapsed;
 }
 
-Geometry*
+std::unique_ptr<Geometry>
 SimpleGeometryPrecisionReducer::reduce(const Geometry* geom)
 {
     GeometryEditor geomEdit;
     PrecisionReducerCoordinateOperation prco(this);
-    Geometry* g = geomEdit.edit(geom, &prco);
-    return g;
+    return geomEdit.edit(geom, &prco);
 }
 
 } // namespace geos.precision

commit 9b7a1db25859f6f5a77b61ebee2bab0163d16b4c
Author: Daniel Baston <dbaston at gmail.com>
Date:   Mon Jun 17 12:30:29 2019 -0400

    Remove trivial heap alloc in GeometryPrecisionReducer

diff --git a/src/precision/GeometryPrecisionReducer.cpp b/src/precision/GeometryPrecisionReducer.cpp
index 80997e3..77bf35a 100644
--- a/src/precision/GeometryPrecisionReducer.cpp
+++ b/src/precision/GeometryPrecisionReducer.cpp
@@ -44,14 +44,7 @@ namespace precision { // geos.precision
 unique_ptr<Geometry>
 GeometryPrecisionReducer::reducePointwise(const Geometry& geom)
 {
-    unique_ptr<GeometryEditor> geomEdit;
-
-    if(newFactory) {
-        geomEdit.reset(new GeometryEditor(newFactory));
-    }
-    else {
-        geomEdit.reset(new GeometryEditor());
-    }
+    GeometryEditor geomEdit(newFactory);
 
     /**
      * For polygonal geometries, collapses are always removed, in order
@@ -64,7 +57,7 @@ GeometryPrecisionReducer::reducePointwise(const Geometry& geom)
 
     PrecisionReducerCoordinateOperation prco(targetPM, finalRemoveCollapsed);
 
-    std::unique_ptr<Geometry> g(geomEdit->edit(&geom, &prco));
+    std::unique_ptr<Geometry> g(geomEdit.edit(&geom, &prco));
 
     return g;
 }

-----------------------------------------------------------------------

Summary of changes:
 include/geos/geom/util/CoordinateOperation.h       | 10 ++--
 include/geos/geom/util/GeometryCombiner.h          |  9 +--
 include/geos/geom/util/GeometryEditor.h            | 15 ++---
 include/geos/geom/util/GeometryEditorOperation.h   |  5 +-
 .../PrecisionReducerCoordinateOperation.h          |  4 +-
 .../precision/SimpleGeometryPrecisionReducer.h     |  3 +-
 src/geom/GeometryFactory.cpp                       |  7 +--
 src/geom/util/CoordinateOperation.cpp              | 26 ++++-----
 src/geom/util/GeometryCombiner.cpp                 | 18 +++---
 src/geom/util/GeometryEditor.cpp                   | 66 +++++++++-------------
 src/operation/union/CascadedPolygonUnion.cpp       |  6 +-
 src/operation/union/CascadedUnion.cpp              |  4 +-
 src/precision/GeometryPrecisionReducer.cpp         | 11 +---
 .../PrecisionReducerCoordinateOperation.cpp        | 21 +++----
 src/precision/SimpleGeometryPrecisionReducer.cpp   | 31 +++++-----
 15 files changed, 104 insertions(+), 132 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list