From 5c0dd8dff361007a9ebb40c28f664af1af4a78d6 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Thu, 25 Oct 2012 18:54:27 +0000 Subject: [PATCH] Allow WKB generation to do direct memcpy of coordinates in specific cases. git-svn-id: http://svn.osgeo.org/postgis/trunk@10562 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/lwout_wkb.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/liblwgeom/lwout_wkb.c b/liblwgeom/lwout_wkb.c index 7005a30ae..648668051 100644 --- a/liblwgeom/lwout_wkb.c +++ b/liblwgeom/lwout_wkb.c @@ -344,19 +344,26 @@ static uint8_t* ptarray_to_wkb_buf(const POINTARRAY *pa, uint8_t *buf, uint8_t v 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. - 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); - dbl_ptr = (double*)getPoint_internal(pa, i); - for ( j = 0; j < dims; j++ ) + /* Bulk copy the coordinates when: dimensionality matches, output format */ + /* is not hex, and output endian matches internal endian. */ + if ( (dims == pa_dims) && ! wkb_swap_bytes(variant) && ! (variant & WKB_HEX) ) + { + size_t size = pa->npoints * dims * WKB_DOUBLE_SIZE; + memcpy(buf, getPoint_internal(pa, 0), size); + buf += size; + } + /* Copy coordinates one-by-one otherwise */ + else + { + for ( i = 0; i < pa->npoints; i++ ) { - LWDEBUGF(4, "Writing dimension #%d (buf = %p)", j, buf); - buf = double_to_wkb_buf(dbl_ptr[j], buf, variant); + LWDEBUGF(4, "Writing point #%d", i); + dbl_ptr = (double*)getPoint_internal(pa, i); + for ( j = 0; j < dims; j++ ) + { + LWDEBUGF(4, "Writing dimension #%d (buf = %p)", j, buf); + buf = double_to_wkb_buf(dbl_ptr[j], buf, variant); + } } } LWDEBUGF(4, "Done (buf = %p)", buf); -- 2.40.0