[postgis-tickets] r15765 - Strip memcpy from int32 access in gserialized,
Paul Ramsey
pramsey at cleverelephant.ca
Tue Sep 19 06:35:44 PDT 2017
Author: pramsey
Date: 2017-09-19 06:35:43 -0700 (Tue, 19 Sep 2017)
New Revision: 15765
Modified:
trunk/liblwgeom/g_serialized.c
trunk/liblwgeom/liblwgeom_internal.h
trunk/liblwgeom/lwgeom_api.c
Log:
Strip memcpy from int32 access in gserialized,
and remove the now-unused functions that support
that operation from the overall internal API.
(Closes #3850)
Modified: trunk/liblwgeom/g_serialized.c
===================================================================
--- trunk/liblwgeom/g_serialized.c 2017-09-18 21:59:57 UTC (rev 15764)
+++ trunk/liblwgeom/g_serialized.c 2017-09-19 13:35:43 UTC (rev 15765)
@@ -30,6 +30,11 @@
/***********************************************************************
* GSERIALIZED metadata utility functions.
*/
+/* handle missaligned uint32_t data */
+static inline uint32_t gserialized_get_uint32_t(const uint8_t *loc)
+{
+ return *((uint32_t*)loc);
+}
int gserialized_has_bbox(const GSERIALIZED *gser)
{
@@ -1209,7 +1214,7 @@
point->flags = g_flags;
data_ptr += 4; /* Skip past the type. */
- npoints = lw_get_uint32_t(data_ptr); /* Zero => empty geometry */
+ npoints = gserialized_get_uint32_t(data_ptr); /* Zero => empty geometry */
data_ptr += 4; /* Skip past the npoints. */
if ( npoints > 0 )
@@ -1240,7 +1245,7 @@
line->flags = g_flags;
data_ptr += 4; /* Skip past the type. */
- npoints = lw_get_uint32_t(data_ptr); /* Zero => empty geometry */
+ npoints = gserialized_get_uint32_t(data_ptr); /* Zero => empty geometry */
data_ptr += 4; /* Skip past the npoints. */
if ( npoints > 0 )
@@ -1274,7 +1279,7 @@
poly->flags = g_flags;
data_ptr += 4; /* Skip past the polygontype. */
- nrings = lw_get_uint32_t(data_ptr); /* Zero => empty geometry */
+ nrings = gserialized_get_uint32_t(data_ptr); /* Zero => empty geometry */
poly->nrings = nrings;
LWDEBUGF(4, "nrings = %d", nrings);
data_ptr += 4; /* Skip past the nrings. */
@@ -1297,7 +1302,7 @@
uint32_t npoints = 0;
/* Read in the number of points. */
- npoints = lw_get_uint32_t(data_ptr);
+ npoints = gserialized_get_uint32_t(data_ptr);
data_ptr += 4;
/* Make a point array for the ring, and move the ordinate pointer past the ring ordinates. */
@@ -1327,7 +1332,7 @@
triangle->flags = g_flags;
data_ptr += 4; /* Skip past the type. */
- npoints = lw_get_uint32_t(data_ptr); /* Zero => empty geometry */
+ npoints = gserialized_get_uint32_t(data_ptr); /* Zero => empty geometry */
data_ptr += 4; /* Skip past the npoints. */
if ( npoints > 0 )
@@ -1358,7 +1363,7 @@
circstring->flags = g_flags;
data_ptr += 4; /* Skip past the circstringtype. */
- npoints = lw_get_uint32_t(data_ptr); /* Zero => empty geometry */
+ npoints = gserialized_get_uint32_t(data_ptr); /* Zero => empty geometry */
data_ptr += 4; /* Skip past the npoints. */
if ( npoints > 0 )
@@ -1384,7 +1389,7 @@
assert(data_ptr);
- type = lw_get_uint32_t(data_ptr);
+ type = gserialized_get_uint32_t(data_ptr);
data_ptr += 4; /* Skip past the type. */
collection = (LWCOLLECTION*)lwalloc(sizeof(LWCOLLECTION));
@@ -1393,7 +1398,7 @@
collection->type = type;
collection->flags = g_flags;
- ngeoms = lw_get_uint32_t(data_ptr);
+ ngeoms = gserialized_get_uint32_t(data_ptr);
collection->ngeoms = ngeoms; /* Zero => empty geometry */
data_ptr += 4; /* Skip past the ngeoms. */
@@ -1407,7 +1412,7 @@
for ( i = 0; i < ngeoms; i++ )
{
- uint32_t subtype = lw_get_uint32_t(data_ptr);
+ uint32_t subtype = gserialized_get_uint32_t(data_ptr);
size_t subsize = 0;
if ( ! lwcollection_allows_subtype(type, subtype) )
@@ -1432,7 +1437,7 @@
assert(data_ptr);
- type = lw_get_uint32_t(data_ptr);
+ type = gserialized_get_uint32_t(data_ptr);
LWDEBUGF(2, "Got type %d (%s), hasz=%d hasm=%d geodetic=%d hasbox=%d", type, lwtype_name(type),
FLAGS_GET_Z(g_flags), FLAGS_GET_M(g_flags), FLAGS_GET_GEODETIC(g_flags), FLAGS_GET_BBOX(g_flags));
Modified: trunk/liblwgeom/liblwgeom_internal.h
===================================================================
--- trunk/liblwgeom/liblwgeom_internal.h 2017-09-18 21:59:57 UTC (rev 15764)
+++ trunk/liblwgeom/liblwgeom_internal.h 2017-09-19 13:35:43 UTC (rev 15765)
@@ -187,12 +187,6 @@
int lwcollection_count_vertices(LWCOLLECTION *col);
/*
-* Read from byte buffer
-*/
-extern uint32_t lw_get_uint32_t(const uint8_t *loc);
-extern int32_t lw_get_int32_t(const uint8_t *loc);
-
-/*
* DP simplification
*/
Modified: trunk/liblwgeom/lwgeom_api.c
===================================================================
--- trunk/liblwgeom/lwgeom_api.c 2017-09-18 21:59:57 UTC (rev 15764)
+++ trunk/liblwgeom/lwgeom_api.c 2017-09-19 13:35:43 UTC (rev 15765)
@@ -578,33 +578,6 @@
}
-
-
-/*****************************************************************************
- * Basic sub-geometry types
- *****************************************************************************/
-
-/* handle missaligned uint32_t32 data */
-uint32_t
-lw_get_uint32_t(const uint8_t *loc)
-{
- uint32_t result;
-
- memcpy(&result, loc, sizeof(uint32_t));
- return result;
-}
-
-/* handle missaligned signed int32_t data */
-int32_t
-lw_get_int32_t(const uint8_t *loc)
-{
- int32_t result;
-
- memcpy(&result,loc, sizeof(int32_t));
- return result;
-}
-
-
/************************************************
* debugging routines
************************************************/
More information about the postgis-tickets
mailing list