From 648fe8424fddab936aaf2fc6783ca1222720ac9d Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Mon, 18 Jun 2012 22:02:30 +0000 Subject: [PATCH] Move the circ tree caching code out of libpgcommon and into the geography area that actually uses it git-svn-id: http://svn.osgeo.org/postgis/trunk@9934 b70326c6-7e19-0410-871a-916f4a2858ee --- libpgcommon/lwgeom_cache.c | 71 --------------------------- libpgcommon/lwgeom_cache.h | 23 --------- postgis/Makefile.in | 1 + postgis/geography_measurement_trees.c | 58 ++++++++++++++++++++++ postgis/geography_measurement_trees.h | 24 +++++++++ 5 files changed, 83 insertions(+), 94 deletions(-) create mode 100644 postgis/geography_measurement_trees.c create mode 100644 postgis/geography_measurement_trees.h diff --git a/libpgcommon/lwgeom_cache.c b/libpgcommon/lwgeom_cache.c index f045f32b3..cfdc85bff 100644 --- a/libpgcommon/lwgeom_cache.c +++ b/libpgcommon/lwgeom_cache.c @@ -224,74 +224,3 @@ GetGeomCache(FunctionCallInfoData* fcinfo, const GeomCacheMethods* cache_methods } -/** -* Builder, freeer and public accessor for cached CIRC_NODE trees -*/ -static int -CircTreeBuilder(const LWGEOM* lwgeom, GeomCache* cache) -{ - CircTreeGeomCache* circ_cache = (CircTreeGeomCache*)cache; - CIRC_NODE* tree = lwgeom_calculate_circ_tree(lwgeom); - - if ( circ_cache->index ) - { - circ_tree_free(circ_cache->index); - circ_cache->index = 0; - } - if ( ! tree ) - return LW_FAILURE; - - circ_cache->index = tree; - return LW_SUCCESS; -} - -static int -CircTreeFreer(GeomCache* cache) -{ - CircTreeGeomCache* circ_cache = (CircTreeGeomCache*)cache; - if ( circ_cache->index ) - { - circ_tree_free(circ_cache->index); - circ_cache->index = 0; - circ_cache->argnum = 0; - } - return LW_SUCCESS; -} - -static GeomCache* -CircTreeAllocator(void) -{ - CircTreeGeomCache* cache = palloc(sizeof(CircTreeGeomCache)); - memset(cache, 0, sizeof(CircTreeGeomCache)); - return (GeomCache*)cache; -} - -static GeomCacheMethods CircTreeCacheMethods = -{ - CIRC_CACHE_ENTRY, - CircTreeBuilder, - CircTreeFreer, - CircTreeAllocator -}; - -CIRC_NODE* -GetCircTree(FunctionCallInfoData* fcinfo, const GSERIALIZED* g1, const GSERIALIZED* g2, int* argnum_of_cache) -{ - CircTreeGeomCache* cache = (CircTreeGeomCache*)GetGeomCache(fcinfo, &CircTreeCacheMethods, g1, g2); - - if ( ! cache ) - return NULL; - - if ( argnum_of_cache ) - *argnum_of_cache = cache->argnum; - - return cache->index; -} - -CircTreeGeomCache* -GetCircTreeGeomCache(FunctionCallInfoData* fcinfo, const GSERIALIZED* g1, const GSERIALIZED* g2) -{ - return (CircTreeGeomCache*)GetGeomCache(fcinfo, &CircTreeCacheMethods, g1, g2); -} - - diff --git a/libpgcommon/lwgeom_cache.h b/libpgcommon/lwgeom_cache.h index 5ea08dff6..115b21228 100644 --- a/libpgcommon/lwgeom_cache.h +++ b/libpgcommon/lwgeom_cache.h @@ -17,9 +17,7 @@ #include "fmgr.h" #include "liblwgeom_internal.h" -#include "lwgeodetic.h" #include "lwgeodetic_tree.h" - #include "lwgeom_pg.h" @@ -47,23 +45,6 @@ typedef struct { int32 argnum; } GeomCache; -/* -* Specific tree types include all the generic slots and -* their own slots for their trees. We put the implementation -* for the CircTreeGeomCache here because we can't shove -* the PgSQL specific bits of the code (fcinfo) back into -* liblwgeom, where most of the circtree logic lives. -*/ -typedef struct { - int type; // - GSERIALIZED* geom1; // - GSERIALIZED* geom2; // - size_t geom1_size; // - size_t geom2_size; // - int32 argnum; // - CIRC_NODE* index; -} CircTreeGeomCache; - /* * Other specific geometry cache types are the * RTreeGeomCache - lwgeom_rtree.h @@ -122,9 +103,5 @@ typedef struct */ PROJ4PortalCache* GetPROJ4SRSCache(FunctionCallInfoData *fcinfo); GeomCache* GetGeomCache(FunctionCallInfoData *fcinfo, const GeomCacheMethods* cache_methods, const GSERIALIZED* g1, const GSERIALIZED* g2); -CIRC_NODE* GetCircTree(FunctionCallInfoData* fcinfo, const GSERIALIZED* g1, const GSERIALIZED* g2, int* argnum_of_cache); -CircTreeGeomCache* GetCircTreeGeomCache(FunctionCallInfoData* fcinfo, const GSERIALIZED* g1, const GSERIALIZED* g2); - - #endif /* LWGEOM_CACHE_H_ */ diff --git a/postgis/Makefile.in b/postgis/Makefile.in index a6d4ea167..43554e076 100644 --- a/postgis/Makefile.in +++ b/postgis/Makefile.in @@ -58,6 +58,7 @@ PG_OBJS= \ geography_btree.o \ geography_estimate.o \ geography_measurement.o \ + geography_measurement_trees.o \ geometry_estimate.o # Objects to build using PGXS diff --git a/postgis/geography_measurement_trees.c b/postgis/geography_measurement_trees.c new file mode 100644 index 000000000..9c9cc7fc5 --- /dev/null +++ b/postgis/geography_measurement_trees.c @@ -0,0 +1,58 @@ +#include "geography_measurement_trees.h" + +/** +* Builder, freeer and public accessor for cached CIRC_NODE trees +*/ +static int +CircTreeBuilder(const LWGEOM* lwgeom, GeomCache* cache) +{ + CircTreeGeomCache* circ_cache = (CircTreeGeomCache*)cache; + CIRC_NODE* tree = lwgeom_calculate_circ_tree(lwgeom); + + if ( circ_cache->index ) + { + circ_tree_free(circ_cache->index); + circ_cache->index = 0; + } + if ( ! tree ) + return LW_FAILURE; + + circ_cache->index = tree; + return LW_SUCCESS; +} + +static int +CircTreeFreer(GeomCache* cache) +{ + CircTreeGeomCache* circ_cache = (CircTreeGeomCache*)cache; + if ( circ_cache->index ) + { + circ_tree_free(circ_cache->index); + circ_cache->index = 0; + circ_cache->argnum = 0; + } + return LW_SUCCESS; +} + +static GeomCache* +CircTreeAllocator(void) +{ + CircTreeGeomCache* cache = palloc(sizeof(CircTreeGeomCache)); + memset(cache, 0, sizeof(CircTreeGeomCache)); + return (GeomCache*)cache; +} + +static GeomCacheMethods CircTreeCacheMethods = +{ + CIRC_CACHE_ENTRY, + CircTreeBuilder, + CircTreeFreer, + CircTreeAllocator +}; + +CircTreeGeomCache* +GetCircTreeGeomCache(FunctionCallInfoData* fcinfo, const GSERIALIZED* g1, const GSERIALIZED* g2) +{ + return (CircTreeGeomCache*)GetGeomCache(fcinfo, &CircTreeCacheMethods, g1, g2); +} + diff --git a/postgis/geography_measurement_trees.h b/postgis/geography_measurement_trees.h new file mode 100644 index 000000000..7ecd26183 --- /dev/null +++ b/postgis/geography_measurement_trees.h @@ -0,0 +1,24 @@ +#include "liblwgeom_internal.h" +#include "lwgeodetic_tree.h" +#include "lwgeom_cache.h" + +/* +* Specific tree types include all the generic slots and +* their own slots for their trees. We put the implementation +* for the CircTreeGeomCache here because we can't shove +* the PgSQL specific bits of the code (fcinfo) back into +* liblwgeom, where most of the circtree logic lives. +*/ +typedef struct { + int type; // + GSERIALIZED* geom1; // + GSERIALIZED* geom2; // + size_t geom1_size; // + size_t geom2_size; // + int32 argnum; // + CIRC_NODE* index; +} CircTreeGeomCache; + + + +CircTreeGeomCache* GetCircTreeGeomCache(FunctionCallInfoData* fcinfo, const GSERIALIZED* g1, const GSERIALIZED* g2); -- 2.40.0