Performance: Reduce num calls to grib_handle_of_accessor

This commit is contained in:
Shahram Najm 2019-08-16 12:31:31 +01:00
parent b8957ba306
commit 071ebde890
7 changed files with 87 additions and 77 deletions

View File

@ -157,22 +157,23 @@ static void init_class(grib_accessor_class* c)
static void init(grib_accessor* a,const long l, grib_arguments* c)
{
grib_accessor_bits* self = (grib_accessor_bits*)a;
grib_handle* hand = grib_handle_of_accessor(a);
grib_expression* e=NULL;
int n = 0;
self->argument = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->start = grib_arguments_get_long(grib_handle_of_accessor(a),c,n++);
self->len = grib_arguments_get_long(grib_handle_of_accessor(a),c,n++);
e=grib_arguments_get_expression(grib_handle_of_accessor(a),c,n++);
self->argument = grib_arguments_get_name(hand,c,n++);
self->start = grib_arguments_get_long(hand,c,n++);
self->len = grib_arguments_get_long(hand,c,n++);
e=grib_arguments_get_expression(hand,c,n++);
if (e) {
grib_expression_evaluate_double(grib_handle_of_accessor(a),e,&(self->referenceValue));
grib_expression_evaluate_double(hand,e,&(self->referenceValue));
self->referenceValuePresent=1;
} else {
self->referenceValuePresent=0;
}
self->scale = 1;
if (self->referenceValuePresent) {
self->scale=grib_arguments_get_double(grib_handle_of_accessor(a),c,n++);
self->scale=grib_arguments_get_double(hand,c,n++);
}
Assert(self->len <= sizeof(long)*8);

View File

@ -173,17 +173,18 @@ typedef double (*decode_float_proc)(unsigned long);
static void init(grib_accessor* a,const long v, grib_arguments* args)
{
grib_accessor_data_sh_packed *self =(grib_accessor_data_sh_packed*)a;
grib_handle* hand = grib_handle_of_accessor(a);
self->GRIBEX_sh_bug_present = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->ieee_floats = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->laplacianOperatorIsSet = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->laplacianOperator = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->sub_j = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->sub_k = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->sub_m = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->pen_j = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->pen_k = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->pen_m = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->GRIBEX_sh_bug_present = grib_arguments_get_name(hand,args,self->carg++);
self->ieee_floats = grib_arguments_get_name(hand,args,self->carg++);
self->laplacianOperatorIsSet = grib_arguments_get_name(hand,args,self->carg++);
self->laplacianOperator = grib_arguments_get_name(hand,args,self->carg++);
self->sub_j = grib_arguments_get_name(hand,args,self->carg++);
self->sub_k = grib_arguments_get_name(hand,args,self->carg++);
self->sub_m = grib_arguments_get_name(hand,args,self->carg++);
self->pen_j = grib_arguments_get_name(hand,args,self->carg++);
self->pen_k = grib_arguments_get_name(hand,args,self->carg++);
self->pen_m = grib_arguments_get_name(hand,args,self->carg++);
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
a->length=0;
@ -192,6 +193,7 @@ static void init(grib_accessor* a,const long v, grib_arguments* args)
static int value_count(grib_accessor* a,long* count)
{
grib_accessor_data_sh_packed *self =(grib_accessor_data_sh_packed*)a;
grib_handle* hand = grib_handle_of_accessor(a);
int ret = 0;
long sub_j= 0;
@ -201,18 +203,18 @@ static int value_count(grib_accessor* a,long* count)
long pen_k= 0;
long pen_m= 0;
if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->sub_j,&sub_j)) != GRIB_SUCCESS)
if((ret = grib_get_long_internal(hand,self->sub_j,&sub_j)) != GRIB_SUCCESS)
return ret;
if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->sub_k,&sub_k)) != GRIB_SUCCESS)
if((ret = grib_get_long_internal(hand,self->sub_k,&sub_k)) != GRIB_SUCCESS)
return ret;
if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->sub_m,&sub_m)) != GRIB_SUCCESS)
if((ret = grib_get_long_internal(hand,self->sub_m,&sub_m)) != GRIB_SUCCESS)
return ret;
if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->pen_j,&pen_j)) != GRIB_SUCCESS)
if((ret = grib_get_long_internal(hand,self->pen_j,&pen_j)) != GRIB_SUCCESS)
return ret;
if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->pen_k,&pen_k)) != GRIB_SUCCESS)
if((ret = grib_get_long_internal(hand,self->pen_k,&pen_k)) != GRIB_SUCCESS)
return ret;
if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->pen_m,&pen_m)) != GRIB_SUCCESS)
if((ret = grib_get_long_internal(hand,self->pen_m,&pen_m)) != GRIB_SUCCESS)
return ret;
if (pen_j != pen_k || pen_j!=pen_m ) {

View File

@ -172,21 +172,22 @@ typedef double (*decode_float_proc)(unsigned long);
static void init(grib_accessor* a,const long v, grib_arguments* args)
{
grib_accessor_data_sh_unpacked *self =(grib_accessor_data_sh_unpacked*)a;
grib_accessor_data_sh_unpacked *self =(grib_accessor_data_sh_unpacked*)a;
grib_handle* hand = grib_handle_of_accessor(a);
self->GRIBEX_sh_bug_present = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->ieee_floats = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->laplacianOperatorIsSet = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->laplacianOperator = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->sub_j = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->sub_k = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->sub_m = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->pen_j = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->pen_k = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->pen_m = grib_arguments_get_name(grib_handle_of_accessor(a),args,self->carg++);
self->GRIBEX_sh_bug_present = grib_arguments_get_name(hand,args,self->carg++);
self->ieee_floats = grib_arguments_get_name(hand,args,self->carg++);
self->laplacianOperatorIsSet = grib_arguments_get_name(hand,args,self->carg++);
self->laplacianOperator = grib_arguments_get_name(hand,args,self->carg++);
self->sub_j = grib_arguments_get_name(hand,args,self->carg++);
self->sub_k = grib_arguments_get_name(hand,args,self->carg++);
self->sub_m = grib_arguments_get_name(hand,args,self->carg++);
self->pen_j = grib_arguments_get_name(hand,args,self->carg++);
self->pen_k = grib_arguments_get_name(hand,args,self->carg++);
self->pen_m = grib_arguments_get_name(hand,args,self->carg++);
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
a->length=0;
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
a->length=0;
}

View File

@ -144,12 +144,13 @@ static void init_class(grib_accessor_class* c)
static void init(grib_accessor* a,const long l, grib_arguments* c)
{
grib_accessor_g1date* self = (grib_accessor_g1date*)a;
grib_handle* hand = grib_handle_of_accessor(a);
int n = 0;
self->century = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->year = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->month = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->day = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->century = grib_arguments_get_name(hand,c,n++);
self->year = grib_arguments_get_name(hand,c,n++);
self->month = grib_arguments_get_name(hand,c,n++);
self->day = grib_arguments_get_name(hand,c,n++);
}
static void dump(grib_accessor* a, grib_dumper* dumper)
@ -161,19 +162,20 @@ static int unpack_long(grib_accessor* a, long* val, size_t *len)
{
int ret=0;
grib_accessor_g1date* self = (grib_accessor_g1date*)a;
grib_handle* hand = grib_handle_of_accessor(a);
long year = 0;
long century = 0;
long month = 0;
long day = 0;
if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->century,&century))!=GRIB_SUCCESS)
if ((ret=grib_get_long_internal(hand, self->century,&century))!=GRIB_SUCCESS)
return ret;
if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->day,&day))!=GRIB_SUCCESS)
if ((ret=grib_get_long_internal(hand, self->day,&day))!=GRIB_SUCCESS)
return ret;
if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->month,&month))!=GRIB_SUCCESS)
if ((ret=grib_get_long_internal(hand, self->month,&month))!=GRIB_SUCCESS)
return ret;
if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->year,&year))!=GRIB_SUCCESS)
if ((ret=grib_get_long_internal(hand, self->year,&year))!=GRIB_SUCCESS)
return ret;
if(*len < 1)
@ -199,6 +201,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t *len)
int ret=0;
long v = val[0];
grib_accessor_g1date* self = (grib_accessor_g1date*)a;
grib_handle* hand = grib_handle_of_accessor(a);
long year = 0;
long century = 0;
@ -227,13 +230,13 @@ static int pack_long(grib_accessor* a, const long* val, size_t *len)
else
century++;
if ((ret=grib_set_long_internal(grib_handle_of_accessor(a),self->century,century))!=GRIB_SUCCESS)
if ((ret=grib_set_long_internal(hand,self->century,century))!=GRIB_SUCCESS)
return ret;
if ((ret=grib_set_long_internal(grib_handle_of_accessor(a),self->day,day))!=GRIB_SUCCESS)
if ((ret=grib_set_long_internal(hand,self->day,day))!=GRIB_SUCCESS)
return ret;
if ((ret=grib_set_long_internal(grib_handle_of_accessor(a),self->month,month))!=GRIB_SUCCESS)
if ((ret=grib_set_long_internal(hand,self->month,month))!=GRIB_SUCCESS)
return ret;
if ((ret=grib_set_long_internal(grib_handle_of_accessor(a),self->year,year))!=GRIB_SUCCESS)
if ((ret=grib_set_long_internal(hand,self->year,year))!=GRIB_SUCCESS)
return ret;
return GRIB_SUCCESS;
@ -250,19 +253,20 @@ static int unpack_string(grib_accessor* a, char* val, size_t *len)
int ret=0;
char tmp[1024];
grib_accessor_g1date* self = (grib_accessor_g1date*)a;
grib_handle* hand = grib_handle_of_accessor(a);
long year = 0;
long century = 0;
long month = 0;
long day = 0;
size_t l;
if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->century,&century))!=GRIB_SUCCESS)
if ((ret=grib_get_long_internal(hand, self->century,&century))!=GRIB_SUCCESS)
return ret;
if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->day,&day))!=GRIB_SUCCESS)
if ((ret=grib_get_long_internal(hand, self->day,&day))!=GRIB_SUCCESS)
return ret;
if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->month,&month))!=GRIB_SUCCESS)
if ((ret=grib_get_long_internal(hand, self->month,&month))!=GRIB_SUCCESS)
return ret;
if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->year,&year))!=GRIB_SUCCESS)
if ((ret=grib_get_long_internal(hand, self->year,&year))!=GRIB_SUCCESS)
return ret;
if(*len < 1)

View File

@ -147,12 +147,14 @@ static void init(grib_accessor* a,const long l, grib_arguments* c)
{
int n=0;
grib_accessor_number_of_values* self = (grib_accessor_number_of_values*)a;
self->values = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->bitsPerValue = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->numberOfPoints = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->bitmapPresent = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->bitmap = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->numberOfCodedValues = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
grib_handle* hand = grib_handle_of_accessor(a);
self->values = grib_arguments_get_name(hand,c,n++);
self->bitsPerValue = grib_arguments_get_name(hand,c,n++);
self->numberOfPoints = grib_arguments_get_name(hand,c,n++);
self->bitmapPresent = grib_arguments_get_name(hand,c,n++);
self->bitmap = grib_arguments_get_name(hand,c,n++);
self->numberOfCodedValues = grib_arguments_get_name(hand,c,n++);
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
a->length=0;

View File

@ -195,14 +195,15 @@ static void init(grib_accessor* a, const long len, grib_arguments* params)
{
int n=0;
grib_accessor_smart_table* self = (grib_accessor_smart_table*)a;
grib_handle* hand = grib_handle_of_accessor(a);
self->values = grib_arguments_get_name(grib_handle_of_accessor(a),params,n++);
self->tablename = grib_arguments_get_string(grib_handle_of_accessor(a),params,n++);
self->masterDir = grib_arguments_get_name(grib_handle_of_accessor(a),params,n++);
self->localDir = grib_arguments_get_name(grib_handle_of_accessor(a),params,n++);
self->widthOfCode = grib_arguments_get_long(grib_handle_of_accessor(a),params,n++);
self->extraDir = grib_arguments_get_name(grib_handle_of_accessor(a),params,n++);
self->extraTable = grib_arguments_get_string(grib_handle_of_accessor(a),params,n++);
self->values = grib_arguments_get_name(hand,params,n++);
self->tablename = grib_arguments_get_string(hand,params,n++);
self->masterDir = grib_arguments_get_name(hand,params,n++);
self->localDir = grib_arguments_get_name(hand,params,n++);
self->widthOfCode = grib_arguments_get_long(hand,params,n++);
self->extraDir = grib_arguments_get_name(hand,params,n++);
self->extraTable = grib_arguments_get_string(hand,params,n++);
a->length = 0;
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
@ -557,5 +558,3 @@ static int unpack_long (grib_accessor* a, long* val, size_t *len)
return err;
}

View File

@ -139,11 +139,12 @@ static void init_class(grib_accessor_class* c)
static void init(grib_accessor* a,const long l, grib_arguments* c)
{
grib_accessor_time* self = (grib_accessor_time*)a;
grib_handle* hand = grib_handle_of_accessor(a);
int n = 0;
self->hour = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->minute = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->second = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
self->hour = grib_arguments_get_name(hand,c,n++);
self->minute = grib_arguments_get_name(hand,c,n++);
self->second = grib_arguments_get_name(hand,c,n++);
}
static void dump(grib_accessor* a, grib_dumper* dumper)
@ -155,16 +156,16 @@ static int unpack_long(grib_accessor* a, long* val, size_t *len)
{
int ret=0;
grib_accessor_time* self = (grib_accessor_time*)a;
long hour = 0;
long minute = 0;
long second = 0;
grib_handle* hand = grib_handle_of_accessor(a);
if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->hour,&hour))!=GRIB_SUCCESS)
if ((ret=grib_get_long_internal(hand, self->hour,&hour))!=GRIB_SUCCESS)
return ret;
if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->minute,&minute))!=GRIB_SUCCESS)
if ((ret=grib_get_long_internal(hand, self->minute,&minute))!=GRIB_SUCCESS)
return ret;
if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->second,&second))!=GRIB_SUCCESS)
if ((ret=grib_get_long_internal(hand, self->second,&second))!=GRIB_SUCCESS)
return ret;
/* We ignore the 'seconds' in our time calculation! */
@ -194,7 +195,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t *len)
int ret=0;
long v = val[0];
grib_accessor_time* self = (grib_accessor_time*)a;
grib_handle* hand = grib_handle_of_accessor(a);
long hour = 0;
long minute = 0;
long second = 0;
@ -206,11 +207,11 @@ static int pack_long(grib_accessor* a, const long* val, size_t *len)
minute = v % 100;
second = 0; /* We ignore the 'seconds' in our time calculation! */
if ((ret=grib_set_long_internal(grib_handle_of_accessor(a),self->hour,hour))!=GRIB_SUCCESS)
if ((ret=grib_set_long_internal(hand,self->hour,hour))!=GRIB_SUCCESS)
return ret;
if ((ret=grib_set_long_internal(grib_handle_of_accessor(a),self->minute,minute))!=GRIB_SUCCESS)
if ((ret=grib_set_long_internal(hand,self->minute,minute))!=GRIB_SUCCESS)
return ret;
if ((ret=grib_set_long_internal(grib_handle_of_accessor(a),self->second,second))!=GRIB_SUCCESS)
if ((ret=grib_set_long_internal(hand,self->second,second))!=GRIB_SUCCESS)
return ret;
return GRIB_SUCCESS;