[postgis-tickets] r16760 - Inline popular functions

Darafei komzpa at gmail.com
Wed Sep 12 07:43:15 PDT 2018


Author: komzpa
Date: 2018-09-12 07:43:15 -0700 (Wed, 12 Sep 2018)
New Revision: 16760

Added:
   trunk/liblwgeom/lwinline.h
Modified:
   trunk/configure.ac
   trunk/liblwgeom/liblwgeom.h.in
   trunk/liblwgeom/lwcircstring.c
   trunk/liblwgeom/lwcollection.c
   trunk/liblwgeom/lwgeom.c
   trunk/liblwgeom/lwgeom_api.c
   trunk/liblwgeom/lwkmeans.c
   trunk/liblwgeom/lwline.c
   trunk/liblwgeom/lwpoint.c
   trunk/liblwgeom/lwpoly.c
   trunk/liblwgeom/lwtriangle.c
   trunk/liblwgeom/lwutil.c
   trunk/liblwgeom/ptarray.c
   trunk/liblwgeom/stringbuffer.c
   trunk/liblwgeom/stringbuffer.h
Log:
Inline popular functions

Gets rid of calls to sqrt, getPoint2d_cp, lwgeom_is_empty, lwgeom_as_lwpoint, stringbuffer_append.

KMeans on 200 000 points is now 30% faster.

Closes https://github.com/postgis/postgis/pull/294



Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2018-09-11 13:17:45 UTC (rev 16759)
+++ trunk/configure.ac	2018-09-12 14:43:15 UTC (rev 16760)
@@ -58,6 +58,9 @@
 PICFLAGS="$lt_prog_compiler_pic"
 AC_SUBST([PICFLAGS])
 
+AC_LIBTOOL_COMPILER_OPTION([if $compiler supports -fno-math-errno], [_cv_nomatherrno], [-fno-math-errno], [], [CFLAGS="$CFLAGS -fno-math-errno"], [])
+AC_LIBTOOL_COMPILER_OPTION([if $compiler supports -fno-signed-zeros], [_cv_nosignedzeros], [-fno-signed-zeros], [], [CFLAGS="$CFLAGS -fno-signed-zeros"], [])
+
 dnl
 dnl For GCC enable additional warning flags -Wall and -Wmissing-prototypes (using macro included with libtool)
 dnl

Modified: trunk/liblwgeom/liblwgeom.h.in
===================================================================
--- trunk/liblwgeom/liblwgeom.h.in	2018-09-11 13:17:45 UTC (rev 16759)
+++ trunk/liblwgeom/liblwgeom.h.in	2018-09-12 14:43:15 UTC (rev 16760)
@@ -597,7 +597,7 @@
 extern LWCOLLECTION *lwgeom_as_lwcollection(const LWGEOM *lwgeom);
 extern LWPOLY *lwgeom_as_lwpoly(const LWGEOM *lwgeom);
 extern LWLINE *lwgeom_as_lwline(const LWGEOM *lwgeom);
-extern LWPOINT *lwgeom_as_lwpoint(const LWGEOM *lwgeom);
+
 extern LWCIRCSTRING *lwgeom_as_lwcircstring(const LWGEOM *lwgeom);
 extern LWCURVEPOLY *lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom);
 extern LWCOMPOUND *lwgeom_as_lwcompound(const LWGEOM *lwgeom);
@@ -831,14 +831,6 @@
 extern int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point);
 
 /**
-* Returns a POINT2D pointer into the POINTARRAY serialized_ptlist,
-* suitable for reading from. This is very high performance
-* and declared const because you aren't allowed to muck with the
-* values, only read them.
-*/
-extern const POINT2D* getPoint2d_cp(const POINTARRAY *pa, uint32_t n);
-
-/**
 * Returns a POINT3DZ pointer into the POINTARRAY serialized_ptlist,
 * suitable for reading from. This is very high performance
 * and declared const because you aren't allowed to muck with the
@@ -864,24 +856,6 @@
  */
 extern void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d);
 
-/*
- * get a pointer to nth point of a POINTARRAY
- * You'll need to cast it to appropriate dimensioned point.
- * Note that if you cast to a higher dimensional point you'll
- * possibly corrupt the POINTARRAY.
- *
- * WARNING: Don't cast this to a POINT !
- * it would not be reliable due to memory alignment constraints
- */
-extern uint8_t *getPoint_internal(const POINTARRAY *pa, uint32_t n);
-
-/*
- * size of point represeneted in the POINTARRAY
- * 16 for 2d, 24 for 3d, 32 for 4d
- */
-extern size_t ptarray_point_size(const POINTARRAY *pa);
-
-
 /**
 * Construct an empty pointarray, allocating storage and setting
 * the npoints, but not filling in any information. Should be used in conjunction
@@ -1179,16 +1153,6 @@
 
 /* general utilities 2D */
 extern double  distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2);
-
-inline static double
-distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
-{
-	double hside = p2->x - p1->x;
-	double vside = p2->y - p1->y;
-
-	return hside * hside + vside * vside;
-}
-
 extern double  distance2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B);
 extern double  distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B);
 extern LWGEOM* lwgeom_closest_line(const LWGEOM *lw1, const LWGEOM *lw2);
@@ -1313,12 +1277,6 @@
 extern int lwgeom_has_srid(const LWGEOM *geom);
 
 /**
-* Return true or false depending on whether a geometry is an "empty"
-* geometry (no vertices members)
-*/
-extern int lwgeom_is_empty(const LWGEOM *geom);
-
-/**
 * Return true or false depending on whether a geometry is a linear
 * feature that closes on itself.
 */
@@ -1410,11 +1368,6 @@
 extern int32_t lwgeom_get_srid(const LWGEOM *geom);
 
 /**
-* Return LWTYPE number
-*/
-extern uint32_t lwgeom_get_type(const LWGEOM *geom);
-
-/**
 * Return #LW_TRUE if geometry has Z ordinates
 */
 extern int lwgeom_has_z(const LWGEOM *geom);
@@ -2422,5 +2375,7 @@
 */
 int * lwgeom_cluster_2d_kmeans(const LWGEOM **geoms, uint32_t ngeoms, uint32_t k);
 
+#include "lwinline.h"
+
 #endif /* !defined _LIBLWGEOM_H  */
 

Modified: trunk/liblwgeom/lwcircstring.c
===================================================================
--- trunk/liblwgeom/lwcircstring.c	2018-09-11 13:17:45 UTC (rev 16759)
+++ trunk/liblwgeom/lwcircstring.c	2018-09-12 14:43:15 UTC (rev 16760)
@@ -266,13 +266,6 @@
 	return ptarray_is_closed_2d(curve->points);
 }
 
-int lwcircstring_is_empty(const LWCIRCSTRING *circ)
-{
-	if ( !circ->points || circ->points->npoints < 1 )
-		return LW_TRUE;
-	return LW_FALSE;
-}
-
 double lwcircstring_length(const LWCIRCSTRING *circ)
 {
 	return lwcircstring_length_2d(circ);

Modified: trunk/liblwgeom/lwcollection.c
===================================================================
--- trunk/liblwgeom/lwcollection.c	2018-09-11 13:17:45 UTC (rev 16759)
+++ trunk/liblwgeom/lwcollection.c	2018-09-12 14:43:15 UTC (rev 16760)
@@ -505,19 +505,7 @@
 	return colout;
 }
 
-int lwcollection_is_empty(const LWCOLLECTION *col)
-{
-	uint32_t i;
-	if ( (col->ngeoms == 0) || (!col->geoms) )
-		return LW_TRUE;
-	for( i = 0; i < col->ngeoms; i++ )
-	{
-		if ( ! lwgeom_is_empty(col->geoms[i]) ) return LW_FALSE;
-	}
-	return LW_TRUE;
-}
 
-
 uint32_t lwcollection_count_vertices(LWCOLLECTION *col)
 {
 	uint32_t i = 0;

Modified: trunk/liblwgeom/lwgeom.c
===================================================================
--- trunk/liblwgeom/lwgeom.c	2018-09-11 13:17:45 UTC (rev 16759)
+++ trunk/liblwgeom/lwgeom.c	2018-09-12 14:43:15 UTC (rev 16760)
@@ -157,15 +157,6 @@
 	}
 }
 
-LWPOINT *
-lwgeom_as_lwpoint(const LWGEOM *lwgeom)
-{
-	if ( lwgeom == NULL ) return NULL;
-	if ( lwgeom->type == POINTTYPE )
-		return (LWPOINT *)lwgeom;
-	else return NULL;
-}
-
 LWLINE *
 lwgeom_as_lwline(const LWGEOM *lwgeom)
 {
@@ -919,13 +910,6 @@
 	return geom->srid;
 }
 
-uint32_t
-lwgeom_get_type(const LWGEOM *geom)
-{
-	if ( ! geom ) return 0;
-	return geom->type;
-}
-
 int
 lwgeom_has_z(const LWGEOM *geom)
 {
@@ -1390,49 +1374,6 @@
 	return result;
 }
 
-int lwgeom_is_empty(const LWGEOM *geom)
-{
-	int result = LW_FALSE;
-	LWDEBUGF(4, "lwgeom_is_empty: got type %s",
-	         lwtype_name(geom->type));
-
-	switch (geom->type)
-	{
-	case POINTTYPE:
-		return lwpoint_is_empty((LWPOINT*)geom);
-		break;
-	case LINETYPE:
-		return lwline_is_empty((LWLINE*)geom);
-		break;
-	case CIRCSTRINGTYPE:
-		return lwcircstring_is_empty((LWCIRCSTRING*)geom);
-		break;
-	case POLYGONTYPE:
-		return lwpoly_is_empty((LWPOLY*)geom);
-		break;
-	case TRIANGLETYPE:
-		return lwtriangle_is_empty((LWTRIANGLE*)geom);
-		break;
-	case MULTIPOINTTYPE:
-	case MULTILINETYPE:
-	case MULTIPOLYGONTYPE:
-	case COMPOUNDTYPE:
-	case CURVEPOLYTYPE:
-	case MULTICURVETYPE:
-	case MULTISURFACETYPE:
-	case POLYHEDRALSURFACETYPE:
-	case TINTYPE:
-	case COLLECTIONTYPE:
-		return lwcollection_is_empty((LWCOLLECTION *)geom);
-		break;
-	default:
-		lwerror("lwgeom_is_empty: unsupported input geometry type: %s",
-		        lwtype_name(geom->type));
-		break;
-	}
-	return result;
-}
-
 int lwgeom_has_srid(const LWGEOM *geom)
 {
 	if ( geom->srid != SRID_UNKNOWN )

Modified: trunk/liblwgeom/lwgeom_api.c
===================================================================
--- trunk/liblwgeom/lwgeom_api.c	2018-09-11 13:17:45 UTC (rev 16759)
+++ trunk/liblwgeom/lwgeom_api.c	2018-09-12 14:43:15 UTC (rev 16760)
@@ -354,26 +354,6 @@
 	return 1;
 }
 
-/**
-* Returns a pointer into the POINTARRAY serialized_ptlist,
-* suitable for reading from. This is very high performance
-* and declared const because you aren't allowed to muck with the
-* values, only read them.
-*/
-const POINT2D*
-getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
-{
-	if ( ! pa ) return 0;
-
-	if ( n>=pa->npoints )
-	{
-		lwerror("getPoint2d_cp: point offset out of range");
-		return 0; /*error */
-	}
-
-	return (const POINT2D*)getPoint_internal(pa, n);
-}
-
 const POINT3DZ*
 getPoint3dz_cp(const POINTARRAY *pa, uint32_t n)
 {

Added: trunk/liblwgeom/lwinline.h
===================================================================
--- trunk/liblwgeom/lwinline.h	                        (rev 0)
+++ trunk/liblwgeom/lwinline.h	2018-09-12 14:43:15 UTC (rev 16760)
@@ -0,0 +1,217 @@
+/**********************************************************************
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.net
+ *
+ * PostGIS is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * PostGIS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PostGIS.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ **********************************************************************
+ *
+ * Copyright 2018 Darafei Praliaskouski <me at komzpa.net>
+ * Copyright 2017-2018 Daniel Baston <dbaston at gmail.com>
+ * Copyright 2011 Sandro Santilli <strk at kbt.io>
+ * Copyright 2011 Paul Ramsey <pramsey at cleverelephant.ca>
+ * Copyright 2007-2008 Mark Cave-Ayland
+ * Copyright 2001-2006 Refractions Research Inc.
+ *
+ **********************************************************************/
+
+#if PARANOIA_LEVEL > 0
+#include <assert.h>
+#endif
+
+inline static double
+distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
+{
+	double hside = p2->x - p1->x;
+	double vside = p2->y - p1->y;
+
+	return hside * hside + vside * vside;
+}
+
+/*
+ * Size of point represeneted in the POINTARRAY
+ * 16 for 2d, 24 for 3d, 32 for 4d
+ */
+static inline size_t
+ptarray_point_size(const POINTARRAY *pa)
+{
+	return sizeof(double) * FLAGS_NDIMS(pa->flags);
+}
+
+/*
+ * Get a pointer to Nth point of a POINTARRAY
+ * You'll need to cast it to appropriate dimensioned point.
+ * Note that if you cast to a higher dimensional point you'll
+ * possibly corrupt the POINTARRAY.
+ *
+ * Casting to returned pointer to POINT2D* should be safe,
+ * as gserialized format always keeps the POINTARRAY pointer
+ * aligned to double boundary.
+ *
+ * WARNING: Don't cast this to a POINT!
+ * it would not be reliable due to memory alignment constraints
+ */
+static inline uint8_t *
+getPoint_internal(const POINTARRAY *pa, uint32_t n)
+{
+	size_t size;
+	uint8_t *ptr;
+
+#if PARANOIA_LEVEL > 0
+	assert(pa);
+	assert(n <= pa->npoints);
+	assert(n < pa->maxpoints);
+#endif
+
+	size = ptarray_point_size(pa);
+	ptr = pa->serialized_pointlist + size * n;
+
+	return ptr;
+}
+
+/**
+ * Returns a POINT2D pointer into the POINTARRAY serialized_ptlist,
+ * suitable for reading from. This is very high performance
+ * and declared const because you aren't allowed to muck with the
+ * values, only read them.
+ */
+static inline const POINT2D *
+getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
+{
+	if (!pa)
+		return 0;
+
+	return (const POINT2D *)getPoint_internal(pa, n);
+}
+
+static inline LWPOINT *
+lwgeom_as_lwpoint(const LWGEOM *lwgeom)
+{
+	if (!lwgeom)
+		return NULL;
+	if (lwgeom->type == POINTTYPE)
+		return (LWPOINT *)lwgeom;
+	else
+		return NULL;
+}
+
+/**
+ * Return LWTYPE number
+ */
+static inline uint32_t
+lwgeom_get_type(const LWGEOM *geom)
+{
+	if (!geom)
+		return 0;
+	return geom->type;
+}
+
+static inline int
+lwpoint_is_empty(const LWPOINT *point)
+{
+	if (!point->point || point->point->npoints < 1)
+		return LW_TRUE;
+	return LW_FALSE;
+}
+
+static inline int
+lwline_is_empty(const LWLINE *line)
+{
+	if (!line->points || line->points->npoints < 1)
+		return LW_TRUE;
+	return LW_FALSE;
+}
+
+static inline int
+lwcircstring_is_empty(const LWCIRCSTRING *circ)
+{
+	if (!circ->points || circ->points->npoints < 1)
+		return LW_TRUE;
+	return LW_FALSE;
+}
+
+static inline int
+lwpoly_is_empty(const LWPOLY *poly)
+{
+	if ((poly->nrings < 1) || (!poly->rings) || (!poly->rings[0]) || (poly->rings[0]->npoints < 1))
+		return LW_TRUE;
+	return LW_FALSE;
+}
+
+static inline int
+lwtriangle_is_empty(const LWTRIANGLE *triangle)
+{
+	if (!triangle->points || triangle->points->npoints < 1)
+		return LW_TRUE;
+	return LW_FALSE;
+}
+
+static inline int lwgeom_is_empty(const LWGEOM *geom);
+
+static inline int
+lwcollection_is_empty(const LWCOLLECTION *col)
+{
+	uint32_t i;
+	if ((col->ngeoms == 0) || (!col->geoms))
+		return LW_TRUE;
+	for (i = 0; i < col->ngeoms; i++)
+	{
+		if (!lwgeom_is_empty(col->geoms[i]))
+			return LW_FALSE;
+	}
+	return LW_TRUE;
+}
+
+/**
+ * Return true or false depending on whether a geometry is an "empty"
+ * geometry (no vertices members)
+ */
+static inline int
+lwgeom_is_empty(const LWGEOM *geom)
+{
+	switch (geom->type)
+	{
+	case POINTTYPE:
+		return lwpoint_is_empty((LWPOINT *)geom);
+		break;
+	case LINETYPE:
+		return lwline_is_empty((LWLINE *)geom);
+		break;
+	case CIRCSTRINGTYPE:
+		return lwcircstring_is_empty((LWCIRCSTRING *)geom);
+		break;
+	case POLYGONTYPE:
+		return lwpoly_is_empty((LWPOLY *)geom);
+		break;
+	case TRIANGLETYPE:
+		return lwtriangle_is_empty((LWTRIANGLE *)geom);
+		break;
+	case MULTIPOINTTYPE:
+	case MULTILINETYPE:
+	case MULTIPOLYGONTYPE:
+	case COMPOUNDTYPE:
+	case CURVEPOLYTYPE:
+	case MULTICURVETYPE:
+	case MULTISURFACETYPE:
+	case POLYHEDRALSURFACETYPE:
+	case TINTYPE:
+	case COLLECTIONTYPE:
+		return lwcollection_is_empty((LWCOLLECTION *)geom);
+		break;
+	default:
+		return LW_FALSE;
+		break;
+	}
+}

Modified: trunk/liblwgeom/lwkmeans.c
===================================================================
--- trunk/liblwgeom/lwkmeans.c	2018-09-11 13:17:45 UTC (rev 16759)
+++ trunk/liblwgeom/lwkmeans.c	2018-09-12 14:43:15 UTC (rev 16760)
@@ -5,9 +5,6 @@
  *
  *------------------------------------------------------------------------*/
 
-#include <float.h>
-#include <math.h>
-
 #include "liblwgeom_internal.h"
 
 /*
@@ -132,7 +129,7 @@
 	uint32_t p1 = 0, p2 = 0;
 	uint32_t i, j;
 	uint32_t duplicate_count = 1; /* a point is a duplicate of itself */
-	double max_dst = -1;
+	double max_dst = -1, current_distance;
 	double dst_p1, dst_p2;
 
 	/* k=0, k=1: "clustering" is just input validation */
@@ -157,11 +154,16 @@
 		dst_p2 = distance2d_sqr_pt_pt(objs[i], objs[p2]);
 		if ((dst_p1 > max_dst) || (dst_p2 > max_dst))
 		{
-			max_dst = fmax(dst_p1, dst_p2);
 			if (dst_p1 > dst_p2)
+			{
+				max_dst = dst_p1;
 				p2 = i;
+			}
 			else
+			{
+				max_dst = dst_p2;
 				p1 = i;
+			}
 		}
 		if ((dst_p1 == 0) || (dst_p2 == 0)) duplicate_count++;
 	}
@@ -209,7 +211,9 @@
 				if (distances[j] < 0) continue;
 
 				/* update minimal distance with previosuly accepted cluster */
-				distances[j] = fmin(distance2d_sqr_pt_pt(objs[j], centers[i - 1]), distances[j]);
+				current_distance = distance2d_sqr_pt_pt(objs[j], centers[i - 1]);
+				if (current_distance < distances[j])
+					distances[j] = current_distance;
 
 				/* greedily take a point that's farthest from any of accepted clusters */
 				if (distances[j] > max_distance)

Modified: trunk/liblwgeom/lwline.c
===================================================================
--- trunk/liblwgeom/lwline.c	2018-09-11 13:17:45 UTC (rev 16759)
+++ trunk/liblwgeom/lwline.c	2018-09-12 14:43:15 UTC (rev 16760)
@@ -508,14 +508,6 @@
 	return lineout;
 }
 
-int lwline_is_empty(const LWLINE *line)
-{
-	if ( !line->points || line->points->npoints < 1 )
-		return LW_TRUE;
-	return LW_FALSE;
-}
-
-
 uint32_t lwline_count_vertices(LWLINE *line)
 {
 	assert(line);

Modified: trunk/liblwgeom/lwpoint.c
===================================================================
--- trunk/liblwgeom/lwpoint.c	2018-09-11 13:17:45 UTC (rev 16759)
+++ trunk/liblwgeom/lwpoint.c	2018-09-12 14:43:15 UTC (rev 16760)
@@ -288,12 +288,4 @@
 	return pointout;
 }
 
-int lwpoint_is_empty(const LWPOINT *point)
-{
-	if ( ! point->point || point->point->npoints < 1 )
-		return LW_TRUE;
-	return LW_FALSE;
-}
 
-
-

Modified: trunk/liblwgeom/lwpoly.c
===================================================================
--- trunk/liblwgeom/lwpoly.c	2018-09-11 13:17:45 UTC (rev 16759)
+++ trunk/liblwgeom/lwpoly.c	2018-09-12 14:43:15 UTC (rev 16760)
@@ -415,13 +415,6 @@
 	return polyout;
 }
 
-int lwpoly_is_empty(const LWPOLY *poly)
-{
-	if ( (poly->nrings < 1) || (!poly->rings) || (!poly->rings[0]) || (poly->rings[0]->npoints < 1) )
-		return LW_TRUE;
-	return LW_FALSE;
-}
-
 uint32_t lwpoly_count_vertices(LWPOLY *poly)
 {
 	uint32_t i = 0;

Modified: trunk/liblwgeom/lwtriangle.c
===================================================================
--- trunk/liblwgeom/lwtriangle.c	2018-09-11 13:17:45 UTC (rev 16759)
+++ trunk/liblwgeom/lwtriangle.c	2018-09-12 14:43:15 UTC (rev 16760)
@@ -171,13 +171,6 @@
 	return ret;
 }
 
-int lwtriangle_is_empty(const LWTRIANGLE *triangle)
-{
-	if ( !triangle->points || triangle->points->npoints < 1 )
-		return LW_TRUE;
-	return LW_FALSE;
-}
-
 /**
  * Find the area of the outer ring
  */

Modified: trunk/liblwgeom/lwutil.c
===================================================================
--- trunk/liblwgeom/lwutil.c	2018-09-11 13:17:45 UTC (rev 16759)
+++ trunk/liblwgeom/lwutil.c	2018-09-12 14:43:15 UTC (rev 16760)
@@ -212,8 +212,6 @@
 	va_end(ap);
 }
 
-
-
 const char*
 lwtype_name(uint8_t type)
 {

Modified: trunk/liblwgeom/ptarray.c
===================================================================
--- trunk/liblwgeom/ptarray.c	2018-09-11 13:17:45 UTC (rev 16759)
+++ trunk/liblwgeom/ptarray.c	2018-09-12 14:43:15 UTC (rev 16760)
@@ -46,18 +46,6 @@
 	return FLAGS_GET_M(pa->flags);
 }
 
-/*
- * Size of point represeneted in the POINTARRAY
- * 16 for 2d, 24 for 3d, 32 for 4d
- */
-inline size_t
-ptarray_point_size(const POINTARRAY *pa)
-{
-	LWDEBUGF(5, "ptarray_point_size: FLAGS_NDIMS(pa->flags)=%x",FLAGS_NDIMS(pa->flags));
-
-	return sizeof(double)*FLAGS_NDIMS(pa->flags);
-}
-
 POINTARRAY*
 ptarray_construct(char hasz, char hasm, uint32_t npoints)
 {
@@ -1738,56 +1726,7 @@
 }
 
 
-/*
- * Get a pointer to nth point of a POINTARRAY.
- *
- * Casting to returned pointer to POINT2D* should be safe,
- * as gserialized format always keeps the POINTARRAY pointer
- * aligned to double boundary.
- */
-uint8_t *
-getPoint_internal(const POINTARRAY *pa, uint32_t n)
-{
-	size_t size;
-	uint8_t *ptr;
 
-#if PARANOIA_LEVEL > 0
-	if ( pa == NULL )
-	{
-		lwerror("%s [%d] got NULL pointarray", __FILE__, __LINE__);
-		return NULL;
-	}
-
-	LWDEBUGF(5, "(n=%d, pa.npoints=%d, pa.maxpoints=%d)",n,pa->npoints,pa->maxpoints);
-
-	if ( ( n > pa->npoints ) ||
-	     ( n >= pa->maxpoints ) )
-	{
-		lwerror("%s [%d] called outside of ptarray range (n=%d, pa.npoints=%d, pa.maxpoints=%d)", __FILE__, __LINE__, n, pa->npoints, pa->maxpoints);
-		return NULL; /*error */
-	}
-#endif
-
-	size = ptarray_point_size(pa);
-
-	ptr = pa->serialized_pointlist + size * n;
-	if ( FLAGS_NDIMS(pa->flags) == 2)
-	{
-		LWDEBUGF(5, "point = %g %g", *((double*)(ptr)), *((double*)(ptr+8)));
-	}
-	else if ( FLAGS_NDIMS(pa->flags) == 3)
-	{
-		LWDEBUGF(5, "point = %g %g %g", *((double*)(ptr)), *((double*)(ptr+8)), *((double*)(ptr+16)));
-	}
-	else if ( FLAGS_NDIMS(pa->flags) == 4)
-	{
-		LWDEBUGF(5, "point = %g %g %g %g", *((double*)(ptr)), *((double*)(ptr+8)), *((double*)(ptr+16)), *((double*)(ptr+24)));
-	}
-
-	return ptr;
-}
-
-
 /**
  * Affine transform a pointarray.
  */

Modified: trunk/liblwgeom/stringbuffer.c
===================================================================
--- trunk/liblwgeom/stringbuffer.c	2018-09-11 13:17:45 UTC (rev 16759)
+++ trunk/liblwgeom/stringbuffer.c	2018-09-12 14:43:15 UTC (rev 16760)
@@ -23,8 +23,6 @@
  *
  **********************************************************************/
 
-
-
 #include "liblwgeom_internal.h"
 #include "stringbuffer.h"
 
@@ -94,28 +92,6 @@
 }
 
 /**
-* If necessary, expand the stringbuffer_t internal buffer to accommodate the
-* specified additional size.
-*/
-static inline void
-stringbuffer_makeroom(stringbuffer_t *s, size_t size_to_add)
-{
-	size_t current_size = (s->str_end - s->str_start);
-	size_t capacity = s->capacity;
-	size_t required_size = current_size + size_to_add;
-
-	while (capacity < required_size)
-		capacity *= 2;
-
-	if ( capacity > s->capacity )
-	{
-		s->str_start = lwrealloc(s->str_start, capacity);
-		s->capacity = capacity;
-		s->str_end = s->str_start + current_size;
-	}
-}
-
-/**
 * Return the last character in the buffer.
 */
 char
@@ -127,18 +103,6 @@
 	return *(s->str_end - 1);
 }
 
-/**
-* Append the specified string to the stringbuffer_t.
-*/
-void
-stringbuffer_append(stringbuffer_t *s, const char *a)
-{
-	int alen = strlen(a); /* Length of string to append */
-	int alen0 = alen + 1; /* Length including null terminator */
-	stringbuffer_makeroom(s, alen0);
-	memcpy(s->str_end, a, alen0);
-	s->str_end += alen;
-}
 
 /**
 * Returns a reference to the internal string being managed by

Modified: trunk/liblwgeom/stringbuffer.h
===================================================================
--- trunk/liblwgeom/stringbuffer.h	2018-09-11 13:17:45 UTC (rev 16759)
+++ trunk/liblwgeom/stringbuffer.h	2018-09-12 14:43:15 UTC (rev 16760)
@@ -27,6 +27,8 @@
 #ifndef _STRINGBUFFER_H
 #define _STRINGBUFFER_H 1
 
+#include "liblwgeom_internal.h"
+
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
@@ -50,7 +52,6 @@
 extern void stringbuffer_clear(stringbuffer_t *sb);
 void stringbuffer_set(stringbuffer_t *sb, const char *s);
 void stringbuffer_copy(stringbuffer_t *sb, stringbuffer_t *src);
-extern void stringbuffer_append(stringbuffer_t *sb, const char *s);
 extern int stringbuffer_aprintf(stringbuffer_t *sb, const char *fmt, ...);
 extern const char *stringbuffer_getstring(stringbuffer_t *sb);
 extern char *stringbuffer_getstringcopy(stringbuffer_t *sb);
@@ -59,4 +60,37 @@
 extern int stringbuffer_trim_trailing_white(stringbuffer_t *s);
 extern int stringbuffer_trim_trailing_zeroes(stringbuffer_t *s);
 
+/**
+ * If necessary, expand the stringbuffer_t internal buffer to accommodate the
+ * specified additional size.
+ */
+static inline void
+stringbuffer_makeroom(stringbuffer_t *s, size_t size_to_add)
+{
+	size_t current_size = (s->str_end - s->str_start);
+	size_t capacity = s->capacity;
+	size_t required_size = current_size + size_to_add;
+
+	while (capacity < required_size)
+		capacity *= 2;
+
+	if (capacity > s->capacity)
+	{
+		s->str_start = lwrealloc(s->str_start, capacity);
+		s->capacity = capacity;
+		s->str_end = s->str_start + current_size;
+	}
+}
+/**
+ * Append the specified string to the stringbuffer_t.
+ */
+inline static void
+stringbuffer_append(stringbuffer_t *s, const char *a)
+{
+	int alen = strlen(a); /* Length of string to append */
+	int alen0 = alen + 1; /* Length including null terminator */
+	stringbuffer_makeroom(s, alen0);
+	memcpy(s->str_end, a, alen0);
+	s->str_end += alen;
+}
 #endif /* _STRINGBUFFER_H */



More information about the postgis-tickets mailing list