]> granicus.if.org Git - postgis/commitdiff
Inline hex conversion of raster wkb in rt_raster_to_hexwkb (#2798)
authorSandro Santilli <strk@keybit.net>
Fri, 4 Jul 2014 16:11:49 +0000 (16:11 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 4 Jul 2014 16:11:49 +0000 (16:11 +0000)
Speeds up importing large rasters.

git-svn-id: http://svn.osgeo.org/postgis/trunk@12724 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_wkb.c

index c34e2fc9fc61fbd47f06ca9d8ae04094a949df3b..21433c4373411380b23bab522da5dda46fe54687 100644 (file)
@@ -670,7 +670,6 @@ char *
 rt_raster_to_hexwkb(rt_raster raster, int outasin, uint32_t *hexwkbsize) {
        uint8_t *wkb = NULL;
        char* hexwkb = NULL;
-       uint32_t i = 0;
        uint32_t wkbsize = 0;
 
        assert(NULL != raster);
@@ -689,11 +688,16 @@ rt_raster_to_hexwkb(rt_raster raster, int outasin, uint32_t *hexwkbsize) {
                rtdealloc(wkb);
                return NULL;
        }
-       hexwkb[*hexwkbsize] = '\0'; /* Null-terminate */
 
-       for (i = 0; i < wkbsize; ++i) {
-               deparse_hex(wkb[i], &(hexwkb[2 * i]));
+       char *optr = hexwkb;
+       uint8_t *iptr = wkb;
+       const char hexchar[]="0123456789ABCDEF";
+       while (wkbsize--) {
+               uint8_t v = *iptr++;
+               *optr++ = hexchar[v>>4];
+               *optr++ = hexchar[v & 0x0F];
        }
+       *optr = '\0'; /* Null-terminate */
 
        rtdealloc(wkb); /* we don't need this anymore */