mirror of https://github.com/ecmwf/eccodes.git
Performance: unpack_string: reduce scope and buffer size
This commit is contained in:
parent
83f7aee39b
commit
0155057ea5
|
@ -347,10 +347,9 @@ static int pack_string_array(grib_accessor* a, const char** v, size_t* len)
|
||||||
static int unpack_string(grib_accessor* a, char* val, size_t* len)
|
static int unpack_string(grib_accessor* a, char* val, size_t* len)
|
||||||
{
|
{
|
||||||
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
|
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
|
||||||
char* str = NULL;
|
char* str = NULL;
|
||||||
char* p = 0;
|
char* p = 0;
|
||||||
size_t slen = 0;
|
size_t slen = 0;
|
||||||
char sval[100] = {0,};
|
|
||||||
double dval = 0;
|
double dval = 0;
|
||||||
size_t dlen = 1;
|
size_t dlen = 1;
|
||||||
|
|
||||||
|
@ -358,6 +357,7 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len)
|
||||||
grib_context* c = a->context;
|
grib_context* c = a->context;
|
||||||
|
|
||||||
if (self->type != BUFR_DESCRIPTOR_TYPE_STRING) {
|
if (self->type != BUFR_DESCRIPTOR_TYPE_STRING) {
|
||||||
|
char sval[32] = {0,};
|
||||||
unpack_double(a, &dval, &dlen);
|
unpack_double(a, &dval, &dlen);
|
||||||
sprintf(sval, "%g", dval);
|
sprintf(sval, "%g", dval);
|
||||||
slen = strlen(sval);
|
slen = strlen(sval);
|
||||||
|
@ -383,7 +383,7 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len)
|
||||||
str = grib_context_strdup(c, self->stringValues->v[idx]->v[0]);
|
str = grib_context_strdup(c, self->stringValues->v[idx]->v[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str == 0 || strlen(str) == 0) {
|
if (str == NULL || strlen(str) == 0) {
|
||||||
grib_context_free(c, str);
|
grib_context_free(c, str);
|
||||||
*len = 0;
|
*len = 0;
|
||||||
*val = 0;
|
*val = 0;
|
||||||
|
|
Loading…
Reference in New Issue