From: Sandro Santilli Date: Fri, 31 Jul 2015 17:23:29 +0000 (+0000) Subject: Add memcmp short-circuit to ST_Equals (#3223) X-Git-Tag: 2.2.0rc1~200 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=66d1d5f9c2f5cf186f62a4c638ada2c1b34ef962;p=postgis Add memcmp short-circuit to ST_Equals (#3223) Patch by Daniel Baston git-svn-id: http://svn.osgeo.org/postgis/trunk@13864 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index 781b5d8d9..b549b7ea0 100644 --- 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) diff --git a/postgis/lwgeom_geos.c b/postgis/lwgeom_geos.c index 2e57e09c1..245ab5fd1 100644 --- a/postgis/lwgeom_geos.c +++ b/postgis/lwgeom_geos.c @@ -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);