[geos-commits] [SCM] GEOS branch master updated. 1357b728c30c6008d6d4fafba158f0cee71f3e9d

git at osgeo.org git at osgeo.org
Thu Apr 30 07:25:02 PDT 2020


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  1357b728c30c6008d6d4fafba158f0cee71f3e9d (commit)
      from  5b7778bf0915e03c3600f536b44d717de861457f (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 1357b728c30c6008d6d4fafba158f0cee71f3e9d
Author: Daniel Baston <dbaston at gmail.com>
Date:   Wed Apr 29 23:43:37 2020 -0400

    Remove manual memory management from FacetSequenceTreeBuilder

diff --git a/include/geos/operation/distance/FacetSequenceTreeBuilder.h b/include/geos/operation/distance/FacetSequenceTreeBuilder.h
index fef2ed3..68026f8 100644
--- a/include/geos/operation/distance/FacetSequenceTreeBuilder.h
+++ b/include/geos/operation/distance/FacetSequenceTreeBuilder.h
@@ -19,6 +19,7 @@
 #ifndef GEOS_OPERATION_DISTANCE_FACETSEQUENCETREEBUILDER_H
 #define GEOS_OPERATION_DISTANCE_FACETSEQUENCETREEBUILDER_H
 
+#include <geos/index/ItemVisitor.h>
 #include <geos/index/strtree/STRtree.h>
 #include <geos/geom/Geometry.h>
 #include <geos/geom/CoordinateSequence.h>
@@ -37,11 +38,35 @@ private:
 
     static void addFacetSequences(const geom::Geometry* geom,
                                   const geom::CoordinateSequence* pts,
-                                  std::vector<FacetSequence*>& sections);
-    static std::vector<FacetSequence*>* computeFacetSequences(const geom::Geometry* g);
+                                  std::vector<std::unique_ptr<FacetSequence>> & sections);
+    static std::vector<std::unique_ptr<FacetSequence>> computeFacetSequences(const geom::Geometry* g);
+
+    class FacetSequenceTree : public geos::index::strtree::STRtree {
+
+        using geos::index::strtree::STRtree::STRtree;
+
+        struct Deleter : public index::ItemVisitor {
+            void
+            visitItem(void* item) override
+            {
+                delete static_cast<FacetSequence*>(item);
+            }
+        } deleter;
+
+    public:
+        ~FacetSequenceTree() override {
+            iterate(deleter);
+        }
+    };
 
 public:
-    static geos::index::strtree::STRtree* build(const geom::Geometry* g);
+    /** \brief
+     * Return a tree of FacetSequences constructed from the supplied Geometry.
+     *
+     * The FacetSequences are owned by the tree and are automatically deleted by
+     * the tree on destruction.
+     */
+    static std::unique_ptr<geos::index::strtree::STRtree> build(const geom::Geometry* g);
 };
 }
 }
diff --git a/include/geos/operation/distance/IndexedFacetDistance.h b/include/geos/operation/distance/IndexedFacetDistance.h
index 0348934..19d7e5b 100644
--- a/include/geos/operation/distance/IndexedFacetDistance.h
+++ b/include/geos/operation/distance/IndexedFacetDistance.h
@@ -98,8 +98,6 @@ public:
     /// \return the nearest points
     std::vector<geom::Coordinate> nearestPoints(const geom::Geometry* g) const;
 
-    ~IndexedFacetDistance();
-
 private:
     std::unique_ptr<geos::index::strtree::STRtree> cachedTree;
 
diff --git a/src/operation/distance/FacetSequenceTreeBuilder.cpp b/src/operation/distance/FacetSequenceTreeBuilder.cpp
index 58e632c..d9c20af 100644
--- a/src/operation/distance/FacetSequenceTreeBuilder.cpp
+++ b/src/operation/distance/FacetSequenceTreeBuilder.cpp
@@ -27,55 +27,55 @@ namespace geos {
 namespace operation {
 namespace distance {
 
-STRtree*
+std::unique_ptr<STRtree>
 FacetSequenceTreeBuilder::build(const Geometry* g)
 {
-    std::unique_ptr<STRtree> tree(new STRtree(STR_TREE_NODE_CAPACITY));
-    std::unique_ptr<std::vector<FacetSequence*> > sections(computeFacetSequences(g));
-    for(std::vector<FacetSequence*>::iterator it = sections->begin(); it != sections->end(); ++it) {
-        FacetSequence* section = *it;
-        tree->insert(section->getEnvelope(), section);
+    auto tree = std::unique_ptr<STRtree>(new FacetSequenceTree(STR_TREE_NODE_CAPACITY));
+    std::vector<std::unique_ptr<FacetSequence>> sections(computeFacetSequences(g));
+
+    for(auto& section : sections) {
+        const Envelope* e = section->getEnvelope();
+        tree->insert(e, section.release());
     }
 
     tree->build();
-    return tree.release();
+    return tree;
 }
 
-std::vector<FacetSequence*>*
+std::vector<std::unique_ptr<FacetSequence>>
 FacetSequenceTreeBuilder::computeFacetSequences(const Geometry* g)
 {
-    std::unique_ptr<std::vector<FacetSequence*> > sections(new std::vector<FacetSequence*>());
+    std::vector<std::unique_ptr<FacetSequence>> sections;
 
-    class FacetSequenceAdder;
     class FacetSequenceAdder : public geom::GeometryComponentFilter {
-        std::vector<FacetSequence*>*  m_sections;
+        std::vector<std::unique_ptr<FacetSequence>>&  m_sections;
 
     public :
-        FacetSequenceAdder(std::vector<FacetSequence*>* p_sections) :
+        FacetSequenceAdder(std::vector<std::unique_ptr<FacetSequence>> & p_sections) :
             m_sections(p_sections) {}
         void
         filter_ro(const Geometry* geom) override
         {
             if(const LineString* ls = dynamic_cast<const LineString*>(geom)) {
                 const CoordinateSequence* seq = ls->getCoordinatesRO();
-                addFacetSequences(geom, seq, *m_sections);
+                addFacetSequences(geom, seq, m_sections);
             }
             else if(const Point* pt = dynamic_cast<const Point*>(geom)) {
                 const CoordinateSequence* seq = pt->getCoordinatesRO();
-                addFacetSequences(geom, seq, *m_sections);
+                addFacetSequences(geom, seq, m_sections);
             }
         }
     };
 
-    FacetSequenceAdder facetSequenceAdder(sections.get());
+    FacetSequenceAdder facetSequenceAdder(sections);
     g->apply_ro(&facetSequenceAdder);
 
-    return sections.release();
+    return sections;
 }
 
 void
 FacetSequenceTreeBuilder::addFacetSequences(const Geometry* geom, const CoordinateSequence* pts,
-        std::vector<FacetSequence*>& sections)
+        std::vector<std::unique_ptr<FacetSequence>> & sections)
 {
     size_t i = 0;
     size_t size = pts->size();
@@ -87,8 +87,8 @@ FacetSequenceTreeBuilder::addFacetSequences(const Geometry* geom, const Coordina
         if(end >= size - 1) {
             end = size;
         }
-        FacetSequence* sect = new FacetSequence(geom, pts, i, end);
-        sections.push_back(sect);
+        std::unique_ptr<FacetSequence> sect = detail::make_unique<FacetSequence>(geom, pts, i, end);
+        sections.emplace_back(std::move(sect));
         i += FACET_SEQUENCE_SIZE;
     }
 }
diff --git a/src/operation/distance/IndexedFacetDistance.cpp b/src/operation/distance/IndexedFacetDistance.cpp
index 7c4877c..ccbf78f 100644
--- a/src/operation/distance/IndexedFacetDistance.cpp
+++ b/src/operation/distance/IndexedFacetDistance.cpp
@@ -17,7 +17,6 @@
  **********************************************************************/
 
 #include <geos/geom/Coordinate.h>
-#include <geos/index/ItemVisitor.h>
 #include <geos/index/strtree/STRtree.h>
 #include <geos/operation/distance/IndexedFacetDistance.h>
 
@@ -27,13 +26,6 @@ using namespace geos::index::strtree;
 namespace geos {
 namespace operation {
 namespace distance {
-struct Deleter : public index::ItemVisitor {
-    void
-    visitItem(void* item) override
-    {
-        delete static_cast<FacetSequence*>(item);
-    }
-} deleter;
 
 /*public static*/
 double
@@ -73,8 +65,6 @@ IndexedFacetDistance::distance(const Geometry* g) const
 
     double p_distance = fs1->distance(*fs2);
 
-    tree2->iterate(deleter);
-
     return p_distance;
 }
 
@@ -96,7 +86,6 @@ IndexedFacetDistance::nearestLocations(const geom::Geometry* g) const
     const FacetSequence *fs2 = static_cast<const FacetSequence*>(obj.second);
     std::vector<GeometryLocation> locs;
     locs = fs1->nearestLocations(*fs2);
-    tree2->iterate(deleter);
     return locs;
 }
 
@@ -110,11 +99,6 @@ IndexedFacetDistance::nearestPoints(const geom::Geometry* g) const
     return nearestPts;
 }
 
-
-IndexedFacetDistance::~IndexedFacetDistance()
-{
-    cachedTree->iterate(deleter);
-}
 }
 }
 }
diff --git a/src/precision/MinimumClearance.cpp b/src/precision/MinimumClearance.cpp
index 26f848b..21d3348 100644
--- a/src/precision/MinimumClearance.cpp
+++ b/src/precision/MinimumClearance.cpp
@@ -23,7 +23,6 @@
 #include <geos/geom/CoordinateArraySequenceFactory.h>
 #include <geos/operation/distance/FacetSequenceTreeBuilder.h>
 #include <geos/geom/LineSegment.h>
-#include <geos/index/ItemVisitor.h>
 
 using namespace geos::geom;
 using namespace geos::operation::distance;
@@ -165,28 +164,6 @@ MinimumClearance::compute()
         }
     };
 
-    struct ItemDeleter : public index::ItemVisitor {
-        void
-        visitItem(void* item) override
-        {
-            delete static_cast<FacetSequence*>(item);
-        }
-    };
-
-    struct ManagedResourceSTRtree {
-        STRtree* m_tree;
-
-        ManagedResourceSTRtree(STRtree* p_tree) : m_tree(p_tree) {}
-
-        ~ManagedResourceSTRtree()
-        {
-            ItemDeleter id;
-            m_tree->iterate(id);
-
-            delete m_tree;
-        }
-    };
-
     // already computed
     if(minClearancePts.get() != nullptr) {
         return;
@@ -202,9 +179,9 @@ MinimumClearance::compute()
         return;
     }
 
-    ManagedResourceSTRtree tree(FacetSequenceTreeBuilder::build(inputGeom));
+    auto tree = FacetSequenceTreeBuilder::build(inputGeom);
     MinClearanceDistance mcd;
-    std::pair<const void*, const void*> nearest = tree.m_tree->nearestNeighbour(&mcd);
+    std::pair<const void*, const void*> nearest = tree->nearestNeighbour(&mcd);
 
     minClearance = mcd.distance(
                        static_cast<const FacetSequence*>(nearest.first),

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

Summary of changes:
 .../operation/distance/FacetSequenceTreeBuilder.h  | 31 ++++++++++++++++--
 .../geos/operation/distance/IndexedFacetDistance.h |  2 --
 .../distance/FacetSequenceTreeBuilder.cpp          | 38 +++++++++++-----------
 src/operation/distance/IndexedFacetDistance.cpp    | 16 ---------
 src/precision/MinimumClearance.cpp                 | 27 ++-------------
 5 files changed, 49 insertions(+), 65 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list