* PostGIS - Spatial Types for PostgreSQL
* http://postgis.refractions.net
*
- * Copyright 2009-2011 Sandro Santilli <strk@keybit.net>
+ * Copyright 2009-2012 Sandro Santilli <strk@keybit.net>
* Copyright 2008 Paul Ramsey <pramsey@cleverelephant.ca>
* Copyright 2001-2003 Refractions Research Inc.
*
#include "lwgeom_rtree.h"
#include "lwgeom_functions_analytic.h" /* for point_in_polygon */
#include "funcapi.h"
+#include "lwgeom_cache.h"
/*
** GEOS prepared geometry is only available from GEOS 3.1 onwards
Datum pgis_union_geometry_array_old(PG_FUNCTION_ARGS);
Datum pgis_union_geometry_array(PG_FUNCTION_ARGS);
-
/*
** Prototypes end
*/
+static RTREE_POLY_CACHE *
+GetRtreeCache(FunctionCallInfoData *fcinfo, LWGEOM *lwgeom, GSERIALIZED *poly)
+{
+ MemoryContext old_context;
+ GeomCache* supercache = GetGeomCache(fcinfo);
+ RTREE_POLY_CACHE *poly_cache = supercache->rtree;
+
+ /*
+ * Switch the context to the function-scope context,
+ * retrieve the appropriate cache object, cache it for
+ * future use, then switch back to the local context.
+ */
+ old_context = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
+ poly_cache = retrieveCache(lwgeom, poly, poly_cache);
+ supercache->rtree = poly_cache;
+ MemoryContextSwitchTo(old_context);
+
+ return poly_cache;
+}
+
PG_FUNCTION_INFO_V1(postgis_geos_version);
Datum postgis_geos_version(PG_FUNCTION_ARGS)
LWGEOM *lwgeom;
LWPOINT *point;
RTREE_POLY_CACHE *poly_cache;
- MemoryContext old_context;
bool result;
#ifdef PREPARED_GEOM
PrepGeomCache *prep_cache;
POSTGIS_DEBUGF(3, "Precall point_in_multipolygon_rtree %p, %p", lwgeom, point);
- /*
- * Switch the context to the function-scope context,
- * retrieve the appropriate cache object, cache it for
- * future use, then switch back to the local context.
- */
- old_context = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
- poly_cache = retrieveCache(lwgeom, geom1, fcinfo->flinfo->fn_extra);
- fcinfo->flinfo->fn_extra = poly_cache;
- MemoryContextSwitchTo(old_context);
+ poly_cache = GetRtreeCache(fcinfo, lwgeom, geom1);
if ( poly_cache->ringIndices )
{
LWGEOM *lwgeom;
LWPOINT *point;
RTREE_POLY_CACHE *poly_cache;
- MemoryContext old_context;
#ifdef PREPARED_GEOM
PrepGeomCache *prep_cache;
#endif
POSTGIS_DEBUGF(3, "Precall point_in_multipolygon_rtree %p, %p", lwgeom, point);
- /*
- * Switch the context to the function-scope context,
- * retrieve the appropriate cache object, cache it for
- * future use, then switch back to the local context.
- */
- old_context = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
- poly_cache = retrieveCache(lwgeom, geom1, fcinfo->flinfo->fn_extra);
- fcinfo->flinfo->fn_extra = poly_cache;
- MemoryContextSwitchTo(old_context);
+ poly_cache = GetRtreeCache(fcinfo, lwgeom, geom1);
if ( poly_cache->ringIndices )
{
LWGEOM *lwgeom;
LWPOINT *point;
int type1, type2;
- MemoryContext old_context;
RTREE_POLY_CACHE *poly_cache;
geom1 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
point = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom1));
lwgeom = lwgeom_from_gserialized(geom2);
- /*
- * Switch the context to the function-scope context,
- * retrieve the appropriate cache object, cache it for
- * future use, then switch back to the local context.
- */
- old_context = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
- poly_cache = retrieveCache(lwgeom, geom2, fcinfo->flinfo->fn_extra);
- fcinfo->flinfo->fn_extra = poly_cache;
- MemoryContextSwitchTo(old_context);
+ poly_cache = GetRtreeCache(fcinfo, lwgeom, geom2);
if ( poly_cache->ringIndices )
{
LWGEOM *lwgeom;
LWPOINT *point;
int type1, type2;
- MemoryContext old_context;
RTREE_POLY_CACHE *poly_cache;
char *patt = "**F**F***";
point = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom1));
lwgeom = lwgeom_from_gserialized(geom2);
- /*
- * Switch the context to the function-scope context,
- * retrieve the appropriate cache object, cache it for
- * future use, then switch back to the local context.
- */
- old_context = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
- poly_cache = retrieveCache(lwgeom, geom2, fcinfo->flinfo->fn_extra);
- fcinfo->flinfo->fn_extra = poly_cache;
- MemoryContextSwitchTo(old_context);
+ poly_cache = GetRtreeCache(fcinfo, lwgeom, geom2);
if ( poly_cache->ringIndices )
{
int type1, type2, polytype;
LWPOINT *point;
LWGEOM *lwgeom;
- MemoryContext old_context;
RTREE_POLY_CACHE *poly_cache;
#ifdef PREPARED_GEOM
PrepGeomCache *prep_cache;
serialized_poly = geom1;
polytype = type1;
}
- /*
- * Switch the context to the function-scope context,
- * retrieve the appropriate cache object, cache it for
- * future use, then switch back to the local context.
- */
- old_context = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
- poly_cache = retrieveCache(lwgeom, serialized_poly, fcinfo->flinfo->fn_extra);
- fcinfo->flinfo->fn_extra = poly_cache;
- MemoryContextSwitchTo(old_context);
+
+ poly_cache = GetRtreeCache(fcinfo, lwgeom, serialized_poly);
if ( poly_cache->ringIndices )
{
* PostGIS - Spatial Types for PostgreSQL
* http://postgis.refractions.net
*
+ * Copyright (C) 2012 Sandro Santilli <strk@keybit.net>
* Copyright (C) 2008 Paul Ramsey <pramsey@cleverelephant.ca>
* Copyright (C) 2007 Refractions Research Inc.
*
*
**********************************************************************/
+#include <assert.h>
+
#include "lwgeom_geos_prepared.h"
+#include "lwgeom_cache.h"
/***********************************************************************
**
GetPrepGeomCache(FunctionCallInfoData *fcinfo, GSERIALIZED *pg_geom1, GSERIALIZED *pg_geom2)
{
MemoryContext old_context;
- PrepGeomCache* cache = fcinfo->flinfo->fn_extra;
+ GeomCache* supercache = GetGeomCache(fcinfo);
+ PrepGeomCache* cache = supercache->prep;
int copy_keys = 1;
size_t pg_geom1_size = 0;
size_t pg_geom2_size = 0;
- /* Make sure this isn't someone else's cache object. */
- if ( cache && cache->type != 2 ) cache = NULL;
+ assert ( ! cache || cache->type == 2 );
if (!PrepGeomHash)
CreatePrepGeomHash();
pghe.prepared_geom = 0;
AddPrepGeomHashEntry( pghe );
- fcinfo->flinfo->fn_extra = cache;
+ supercache->prep = cache;
POSTGIS_DEBUGF(3, "GetPrepGeomCache: adding context to hash: %p", cache);
}