[geos-commits] [SCM] GEOS branch master updated. 395e6c2d2531eda7483dd137058041f830e33825

git at osgeo.org git at osgeo.org
Sun Jan 17 09:11:53 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  395e6c2d2531eda7483dd137058041f830e33825 (commit)
      from  dae18d6c6555b4b129ec053af3a50f7045fd5413 (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 395e6c2d2531eda7483dd137058041f830e33825
Author: Martin Davis <mtnclimb at gmail.com>
Date:   Sun Jan 17 09:11:45 2021 -0800

    Add geosop PreparedGeometryCache class

diff --git a/util/geosop/GeomFunction.cpp b/util/geosop/GeomFunction.cpp
index ccd1b75..176dbcc 100644
--- a/util/geosop/GeomFunction.cpp
+++ b/util/geosop/GeomFunction.cpp
@@ -46,8 +46,26 @@ using geos::operation::overlayng::OverlayNG;
 /* static private */
 std::map<std::string, GeomFunction*> GeomFunction::registry;
 
-static std::unique_ptr<const PreparedGeometry> prepGeomCache;
-static Geometry *cacheKey;
+class PreparedGeometryCache {
+public:
+    const PreparedGeometry* get(const Geometry* key) {
+        if (m_key != key) {
+            m_pg = PreparedGeometryFactory::prepare(key);
+            m_key = key;
+        }
+
+        return m_pg.get();
+    }
+
+private:
+    std::unique_ptr<const PreparedGeometry> m_pg;
+    const Geometry* m_key;
+};
+
+PreparedGeometryCache prepGeomCache;
+
+//static std::unique_ptr<const PreparedGeometry> prepGeomCache;
+//static Geometry *cacheKey;
 
 /* static */
 void
@@ -236,64 +254,28 @@ GeomFunction::init()
 
     add("containsPrep", "tests if geometry A contains geometry B, using PreparedGeometry", 2, 0,
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
-            if (cacheKey == nullptr || cacheKey != geom.get()) {
-                auto pg = std::unique_ptr<const PreparedGeometry>(
-                    PreparedGeometryFactory::prepare( geom.get()) );
-                prepGeomCache = std::move( pg );
-                cacheKey = geom.get();
-            }
-            return new Result( prepGeomCache->contains( geomB.get() ) );
+            return new Result( prepGeomCache.get(geom.get())->contains( geomB.get() ) );
         });
     add("containsProperlyPrep", "tests if geometry A properly contains geometry B using PreparedGeometry", 2, 0,
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
-            if (cacheKey == nullptr || cacheKey != geom.get()) {
-                auto pg = std::unique_ptr<const PreparedGeometry>(
-                    PreparedGeometryFactory::prepare( geom.get()) );
-                prepGeomCache = std::move( pg );
-                cacheKey = geom.get();
-            }
-            return new Result( prepGeomCache->containsProperly( geomB.get() ) );
+            return new Result( prepGeomCache.get(geom.get())->containsProperly( geomB.get() ) );
         });
     add("coversPrep", "tests if geometry A covers geometry B using PreparedGeometry", 2, 0,
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
-            if (cacheKey == nullptr || cacheKey != geom.get()) {
-                auto pg = std::unique_ptr<const PreparedGeometry>(
-                    PreparedGeometryFactory::prepare( geom.get()) );
-                prepGeomCache = std::move( pg );
-                cacheKey = geom.get();
-            }
-            return new Result( prepGeomCache->covers( geomB.get() ) );
+            return new Result( prepGeomCache.get(geom.get())->covers( geomB.get() ) );
         });
     add("intersectsPrep", "tests if geometry A intersects B using PreparedGeometry", 2, 0,
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
-            if (cacheKey == nullptr || cacheKey != geom.get()) {
-                auto pg = std::unique_ptr<const PreparedGeometry>(
-                    PreparedGeometryFactory::prepare( geom.get()) );
-                prepGeomCache = std::move( pg );
-                cacheKey = geom.get();
-            }
-            return new Result( prepGeomCache->intersects( geomB.get() ) );
+            return new Result( prepGeomCache.get(geom.get())->intersects( geomB.get() ) );
         });
 
     add("distancePrep", "computes distance between geometry A and B using PreparedGeometry", 2, 0,
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
-            if (cacheKey == nullptr || cacheKey != geom.get()) {
-                auto pg = std::unique_ptr<const PreparedGeometry>(
-                    PreparedGeometryFactory::prepare( geom.get()) );
-                prepGeomCache = std::move( pg );
-                cacheKey = geom.get();
-            }
-            return new Result( prepGeomCache->distance( geomB.get() ) );
+            return new Result( prepGeomCache.get(geom.get())->distance( geomB.get() ) );
         });
     add("nearestPointsPrep", "computes nearest points of geometry A and B using PreparedGeometry", 2, 0,
         [](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
-            if (cacheKey == nullptr || cacheKey != geom.get()) {
-                auto pg = std::unique_ptr<const PreparedGeometry>(
-                    PreparedGeometryFactory::prepare( geom.get()) );
-                prepGeomCache = std::move( pg );
-                cacheKey = geom.get();
-            }
-            auto cs = prepGeomCache->nearestPoints( geomB.get() );
+            auto cs = prepGeomCache.get(geom.get())->nearestPoints( geomB.get() );
             auto factory = geom->getFactory();
             auto res = factory->createLineString( std::move(cs) );
             return new Result( std::move(res) );
diff --git a/util/geosop/GeosOp.cpp b/util/geosop/GeosOp.cpp
index ce30bf7..11d71dc 100644
--- a/util/geosop/GeosOp.cpp
+++ b/util/geosop/GeosOp.cpp
@@ -333,7 +333,7 @@ void GeosOp::run() {
 
     if (args.isShowTime || args.isVerbose) {
         std::cout
-            << "Processed " <<  formatNum( opCount ) << " " << args.opName << " ops ( "
+            << "Ran " <<  formatNum( opCount ) << " " << args.opName << " ops ( "
             << formatNum( vertexCount ) << " vertices)"
             << "  -- " << formatNum( totalTime ) <<  " usec"
             << "    (GEOS " << geosversion() << ")"

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

Summary of changes:
 util/geosop/GeomFunction.cpp | 70 ++++++++++++++++----------------------------
 util/geosop/GeosOp.cpp       |  2 +-
 2 files changed, 27 insertions(+), 45 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list