From 811304a8b1bcc59dbc82d15cbb04029698cd1d2e Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Thu, 25 Oct 2012 18:42:16 +0000 Subject: [PATCH] Use double alignment property to remove memcpy from wkb generation git-svn-id: http://svn.osgeo.org/postgis/trunk@10561 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/lwout_wkb.c | 9 ++++++--- liblwgeom/lwout_wkt.c | 6 ++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/liblwgeom/lwout_wkb.c b/liblwgeom/lwout_wkb.c index b85bbf517..7005a30ae 100644 --- a/liblwgeom/lwout_wkb.c +++ b/liblwgeom/lwout_wkb.c @@ -332,20 +332,23 @@ static size_t ptarray_to_wkb_size(const POINTARRAY *pa, uint8_t variant) static uint8_t* ptarray_to_wkb_buf(const POINTARRAY *pa, uint8_t *buf, uint8_t variant) { int dims = 2; + int pa_dims = FLAGS_NDIMS(pa->flags); int i, j; double *dbl_ptr; /* SFSQL is always 2-d. Extended and ISO use all available dimensions */ if ( (variant & WKB_ISO) || (variant & WKB_EXTENDED) ) - dims = FLAGS_NDIMS(pa->flags); + dims = pa_dims; /* Set the number of points (if it's not a POINT type) */ if ( ! ( variant & WKB_NO_NPOINTS ) ) buf = integer_to_wkb_buf(pa->npoints, buf, variant); /* Set the ordinates. */ - /* TODO: Make this faster by bulk copying the coordinates when - the output endian/dims match the internal endian/dims */ + /* TODO: Make this faster by bulk copying the coordinates. + Can only do this when: wkb/pa dimensions match, + output is not hex-encoded, and + machine endian matches requested endianness. */ for ( i = 0; i < pa->npoints; i++ ) { LWDEBUGF(4, "Writing point #%d", i); diff --git a/liblwgeom/lwout_wkt.c b/liblwgeom/lwout_wkt.c index 7efb17da3..77c9025a7 100644 --- a/liblwgeom/lwout_wkt.c +++ b/liblwgeom/lwout_wkt.c @@ -83,8 +83,7 @@ static void ptarray_to_wkt_sb(const POINTARRAY *ptarray, stringbuffer_t *sb, int /* Digits and commas */ for (i = 0; i < ptarray->npoints; i++) { - uint8_t *p = getPoint_internal(ptarray, i); - double d; + double *dbl_ptr = (double*)getPoint_internal(ptarray, i); /* Commas before ever coord but the first */ if ( i > 0 ) @@ -92,11 +91,10 @@ static void ptarray_to_wkt_sb(const POINTARRAY *ptarray, stringbuffer_t *sb, int for (j = 0; j < dimensions; j++) { - memcpy(&d, p + j * sizeof(double), sizeof(double)); /* Spaces before every ordinate but the first */ if ( j > 0 ) stringbuffer_append(sb, " "); - stringbuffer_aprintf(sb, "%.*g", precision, d); + stringbuffer_aprintf(sb, "%.*g", precision, dbl_ptr[j]); } } -- 2.40.0