PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ PrepGeomCacheBuilder()

static int PrepGeomCacheBuilder ( const LWGEOM lwgeom,
GeomCache *  cache 
)
static

Given a generic GeomCache, and a geometry to prepare, prepare a PrepGeomCache and stick it into the GeomCache->index slot.

The PrepGeomCache includes the original GEOS geometry, and the GEOS prepared geometry, and a pointer to the MemoryContext where the callback functions are registered.

This function is passed into the generic GetGeomCache function so that it can build an appropriate indexed structure in the case of a cache hit when there is no indexed structure yet available to return.

Definition at line 299 of file lwgeom_geos_prepared.c.

300{
301 PrepGeomCache* prepcache = (PrepGeomCache*)cache;
302 PrepGeomHashEntry* pghe;
303
304 /*
305 * First time through? allocate the global hash.
306 */
307 if (!PrepGeomHash)
309
310 /*
311 * No callback entry for this statement context yet? Set it up
312 */
313 if ( ! prepcache->context_callback )
314 {
316#if POSTGIS_PGSQL_VERSION < 96
317 prepcache->context_callback = MemoryContextCreate(T_AllocSetContext, 8192,
318 &PreparedCacheContextMethods,
319 prepcache->context_statement,
320 "PostGIS Prepared Geometry Context");
321
322#else
323 MemoryContextCallback *callback;
324 prepcache->context_callback = AllocSetContextCreate(prepcache->context_statement,
325 "PostGIS Prepared Geometry Context",
326 ALLOCSET_SMALL_SIZES);
327
328 /* PgSQL comments suggest allocating callback in the context */
329 /* being managed, so that the callback object gets cleaned along with */
330 /* the context */
331 callback = MemoryContextAlloc(prepcache->context_callback, sizeof(MemoryContextCallback));
332 callback->arg = (void*)(prepcache->context_callback);
333 callback->func = PreparedCacheDelete;
334 MemoryContextRegisterResetCallback(prepcache->context_callback, callback);
335#endif
336
337 pghe.context = prepcache->context_callback;
338 pghe.geom = 0;
339 pghe.prepared_geom = 0;
340 AddPrepGeomHashEntry( pghe );
341 }
342
343 /*
344 * Hum, we shouldn't be asked to build a new cache on top of
345 * an existing one. Error.
346 */
347 if ( prepcache->gcache.argnum || prepcache->geom || prepcache->prepared_geom )
348 {
349 lwpgerror("PrepGeomCacheBuilder asked to build new prepcache where one already exists.");
350 return LW_FAILURE;
351 }
352
353 prepcache->geom = LWGEOM2GEOS( lwgeom , 0);
354 if ( ! prepcache->geom ) return LW_FAILURE;
355 prepcache->prepared_geom = GEOSPrepare( prepcache->geom );
356 if ( ! prepcache->prepared_geom ) return LW_FAILURE;
357 prepcache->gcache.argnum = cache->argnum;
358
359 /*
360 * In order to find the objects we need to destroy, we keep
361 * extra references in a global hash object.
362 */
363 pghe = GetPrepGeomHashEntry(prepcache->context_callback);
364 if ( ! pghe )
365 {
366 lwpgerror("PrepGeomCacheBuilder failed to find hash entry for context %p", prepcache->context_callback);
367 return LW_FAILURE;
368 }
369
370 pghe->geom = prepcache->geom;
371 pghe->prepared_geom = prepcache->prepared_geom;
372
373 return LW_SUCCESS;
374}
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
#define LW_FAILURE
Definition liblwgeom.h:110
#define LW_SUCCESS
Definition liblwgeom.h:111
static void CreatePrepGeomHash(void)
static HTAB * PrepGeomHash
static void AddPrepGeomHashEntry(PrepGeomHashEntry pghe)
static void PreparedCacheDelete(void *ptr)
static PrepGeomHashEntry * GetPrepGeomHashEntry(MemoryContext mcxt)
const GEOSPreparedGeometry * prepared_geom
MemoryContext context_statement
const GEOSGeometry * geom
MemoryContext context_callback
const GEOSGeometry * geom
const GEOSPreparedGeometry * prepared_geom

References AddPrepGeomHashEntry(), PrepGeomHashEntry::context, PrepGeomCache::context_callback, PrepGeomCache::context_statement, CreatePrepGeomHash(), PrepGeomCache::gcache, PrepGeomHashEntry::geom, PrepGeomCache::geom, GetPrepGeomHashEntry(), LW_FAILURE, LW_SUCCESS, LWGEOM2GEOS(), PrepGeomHashEntry::prepared_geom, PrepGeomCache::prepared_geom, PreparedCacheDelete(), and PrepGeomHash.

Here is the call graph for this function: