]> granicus.if.org Git - postgis/commitdiff
Add memcmp short-circuit to ST_Equals (#3223)
authorSandro Santilli <strk@keybit.net>
Fri, 31 Jul 2015 17:23:29 +0000 (17:23 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 31 Jul 2015 17:23:29 +0000 (17:23 +0000)
Patch by Daniel Baston

git-svn-id: http://svn.osgeo.org/postgis/trunk@13864 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
postgis/lwgeom_geos.c

diff --git a/NEWS b/NEWS
index 781b5d8d91bf6e6c822a1d12752d45ab8eaeece2..b549b7ea06b7517d1f17ec5bae007e39a4e2a275 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -96,6 +96,7 @@ PostGIS 2.2.0
 
  * Enhancements *
 
+  - #3223, Add memcmp short-circuit to ST_Equals (Daniel Baston)
   - #2278, Make liblwgeom compatible between minor releases
   - #897, ST_AsX3D support for GeoCoordinates and systems "GD" "WE"
            ability to flip x/y axis (use option = 2, 3)
index 2e57e09c16bcc1470c7473c70d8eee7eb91cfd00..245ab5fd18052fe533896f3fb1af87f7a6f136b1 100644 (file)
@@ -3097,6 +3097,14 @@ Datum ST_Equals(PG_FUNCTION_ARGS)
                }
        }
 
+       /*
+        * short-circuit: if geom1 and geom2 are binary-equivalent, we can return
+        * TRUE.  This is much faster than doing the comparison using GEOS.
+        */
+       if (VARSIZE(geom1) == VARSIZE(geom2) && !memcmp(geom1, geom2, VARSIZE(geom1))) {
+           PG_RETURN_BOOL(TRUE);
+       }
+
        initGEOS(lwpgnotice, lwgeom_geos_error);
 
        g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);