BUFR decode performance: JSON bufr_dump much slower than plain mode
@@ -411,27 +411,30 @@ static void dump_string_array(grib_dumper* d,grib_accessor* a,const char* commen
(void)err; /* TODO */
}
+# define MAX_STRING_SIZE 4096
static void dump_string(grib_dumper* d,grib_accessor* a,const char* comment)
{
grib_dumper_json *self = (grib_dumper_json*)d;
- char *value = NULL;
+ char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */
char *p = NULL;
- size_t size = 0;
+ size_t size = MAX_STRING_SIZE;
int is_missing = 0;
- grib_context* c = NULL;
- int err = _grib_get_string_length(a,&size);
-
- c = a->context;
- if (size==0) return;
+ int err = 0;
- if ( (a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0)
+ if ( (a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) {
return;
+ }
- value=(char*)grib_context_malloc_clear(c,size);
+ /* ECC-710: It is MUCH slower determining the string length here
+ * than using a maximum size (and no need for malloc).
+ * Specially for BUFR elements */
+ /*err = _grib_get_string_length(a,&size);
+ if (size==0) return;
+ value=(char*)grib_context_malloc_clear(a->context,size);
if (!value) {
- grib_context_log(c,GRIB_LOG_FATAL,"unable to allocate %d bytes",(int)size);
+ grib_context_log(a->context,GRIB_LOG_FATAL,"unable to allocate %d bytes",(int)size);
return;
- }
+ }*/
if (self->begin==0 && self->empty==0 && self->isAttribute==0) fprintf(self->dumper.out,",");
else self->begin=0;
@@ -439,6 +442,7 @@ static void dump_string(grib_dumper* d,grib_accessor* a,const char* comment)
self->empty=0;
err = grib_unpack_string(a,value,&size);
+ Assert(size < MAX_STRING_SIZE);
p=value;
if (grib_is_missing_string(a,(unsigned char *)value,size)) {
is_missing = 1;
@@ -465,7 +469,7 @@ static void dump_string(grib_dumper* d,grib_accessor* a,const char* comment)
fprintf(self->dumper.out,"\n%-*s}",depth," ");
}
- grib_context_free(c,value);
+ /*grib_context_free(a->context,value);*/
(void)err; /* TODO */
}
