]> granicus.if.org Git - postgis/commitdiff
Use double alignment property to remove memcpy from wkb generation
authorPaul Ramsey <pramsey@cleverelephant.ca>
Thu, 25 Oct 2012 18:42:16 +0000 (18:42 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Thu, 25 Oct 2012 18:42:16 +0000 (18:42 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@10561 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwout_wkb.c
liblwgeom/lwout_wkt.c

index b85bbf517c6492eddb016fb390f35a874adb4e2f..7005a30ae0e03816081b7e5bb25dfbbb9c1379bb 100644 (file)
@@ -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);
index 7efb17da30f60642667cba016c4ae2be10502cb7..77c9025a79ffb7204b5a5a4282756e987f04ae00 100644 (file)
@@ -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]);
                }
        }