[geos-commits] [SCM] GEOS branch master updated. e282cbe1e774d22f43c3acfdcd98d820acc32201

git at osgeo.org git at osgeo.org
Sun Mar 7 09:31:13 PST 2021


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  e282cbe1e774d22f43c3acfdcd98d820acc32201 (commit)
      from  d2482e91dd35ebbf3f992e5338809d44767a0340 (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 e282cbe1e774d22f43c3acfdcd98d820acc32201
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sat Mar 6 18:37:04 2021 -0500

    Reduce heap allocs in SegmentNodeList
    
    createSplitPts is usually returning a vector of length 2, so switch to a
    FixedCoordinateSequence instead.

diff --git a/include/geos/noding/SegmentNodeList.h b/include/geos/noding/SegmentNodeList.h
index a8c1407..d3644ac 100644
--- a/include/geos/noding/SegmentNodeList.h
+++ b/include/geos/noding/SegmentNodeList.h
@@ -95,7 +95,7 @@ private:
     * @param ei1 the end node of the split edge
     * @return the points for the split edge
     */
-    void createSplitEdgePts(const SegmentNode* ei0, const SegmentNode* ei1, std::vector<geom::Coordinate>& pts) const;
+    std::unique_ptr<geom::CoordinateSequence> createSplitEdgePts(const SegmentNode* ei0, const SegmentNode* ei1) const;
 
     /**
      * Adds nodes for any collapsed edge pairs.
diff --git a/src/noding/SegmentNodeList.cpp b/src/noding/SegmentNodeList.cpp
index 84c49dd..b6c3391 100644
--- a/src/noding/SegmentNodeList.cpp
+++ b/src/noding/SegmentNodeList.cpp
@@ -30,6 +30,7 @@
 #include <geos/geom/Coordinate.h>
 #include <geos/geom/CoordinateSequence.h>
 #include <geos/geom/CoordinateArraySequence.h> // FIXME: should we really be using this ?
+#include <geos/geom/FixedSizeCoordinateSequence.h>
 
 #ifndef GEOS_DEBUG
 #define GEOS_DEBUG 0
@@ -241,24 +242,23 @@ SegmentNodeList::checkSplitEdgesCorrectness(const std::vector<SegmentString*>& s
 std::unique_ptr<SegmentString>
 SegmentNodeList::createSplitEdge(const SegmentNode* ei0, const SegmentNode* ei1) const
 {
-    std::vector<Coordinate> pts;
-    createSplitEdgePts(ei0, ei1, pts);
-    return detail::make_unique<NodedSegmentString>(new CoordinateArraySequence(std::move(pts)), edge.getData());
+    auto pts = createSplitEdgePts(ei0, ei1);
+    return detail::make_unique<NodedSegmentString>(pts.release(), edge.getData());
 }
 
 
 /*private*/
-void
-SegmentNodeList::createSplitEdgePts(const SegmentNode* ei0, const SegmentNode* ei1, std::vector<Coordinate>& pts) const
+std::unique_ptr<CoordinateSequence>
+SegmentNodeList::createSplitEdgePts(const SegmentNode* ei0, const SegmentNode* ei1) const
 {
-    //int npts = ei1->segmentIndex - (ei0->segmentIndex + 2);
     bool twoPoints = (ei1->segmentIndex == ei0->segmentIndex);
 
     // if only two points in split edge they must be the node points
     if (twoPoints) {
-        pts.emplace_back(ei0->coord);
-        pts.emplace_back(ei1->coord);
-        return;
+        auto pts = detail::make_unique<FixedSizeCoordinateSequence<2>>();
+        pts->setAt(ei0->coord, 0);
+        pts->setAt(ei1->coord, 1);
+        return RETURN_UNIQUE_PTR(pts);
     }
 
     const Coordinate& lastSegStartPt = edge.getCoordinate(ei1->segmentIndex);
@@ -270,9 +270,9 @@ SegmentNodeList::createSplitEdgePts(const SegmentNode* ei0, const SegmentNode* e
     * The check for point equality is 2D only - Z values are ignored
     */
     bool useIntPt1 = ei1->isInterior() || ! ei1->coord.equals2D(lastSegStartPt);
-    //if (!useIntPt1) {
-    //    npts--;
-    //}
+
+    std::vector<Coordinate> pts;
+    pts.reserve(1 + (ei1->segmentIndex - ei0->segmentIndex) + useIntPt1);
 
     pts.emplace_back(ei0->coord);
     for (std::size_t i = ei0->segmentIndex + 1; i <= ei1->segmentIndex; i++) {
@@ -281,6 +281,8 @@ SegmentNodeList::createSplitEdgePts(const SegmentNode* ei0, const SegmentNode* e
     if (useIntPt1) {
         pts.emplace_back(ei1->coord);
     }
+
+    return std::unique_ptr<CoordinateSequence>(new CoordinateArraySequence(std::move(pts)));
 }
 
 
@@ -306,10 +308,9 @@ SegmentNodeList::getSplitCoordinates()
 /*private*/
 void
 SegmentNodeList::addEdgeCoordinates(const SegmentNode* ei0, const SegmentNode* ei1, std::vector<Coordinate>& coordList) const {
-    std::vector<Coordinate> pts;
-    createSplitEdgePts(ei0, ei1, pts);
+    auto pts = createSplitEdgePts(ei0, ei1);
     // Append pts to coordList
-    coordList.insert(coordList.end(), pts.begin(), pts.end());
+    pts->toVector(coordList);
     // Remove duplicate Coordinates from coordList
     coordList.erase(std::unique(coordList.begin(), coordList.end()), coordList.end());
 }

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

Summary of changes:
 include/geos/noding/SegmentNodeList.h |  2 +-
 src/noding/SegmentNodeList.cpp        | 31 ++++++++++++++++---------------
 2 files changed, 17 insertions(+), 16 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list