From 4dd138f3e0f5bee069b3a4e43365cf0ae9884fa6 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 9 Aug 2019 16:45:22 +0100 Subject: [PATCH] Reduce calls to grib_handle_of_accessor --- src/grib_accessor_class_g2grid.c | 52 +++++++++++++------------ src/grib_accessor_class_validity_date.c | 32 ++++++++------- src/grib_accessor_class_validity_time.c | 28 ++++++------- 3 files changed, 59 insertions(+), 53 deletions(-) diff --git a/src/grib_accessor_class_g2grid.c b/src/grib_accessor_class_g2grid.c index ff1e9fc27..cca4bb776 100644 --- a/src/grib_accessor_class_g2grid.c +++ b/src/grib_accessor_class_g2grid.c @@ -156,16 +156,17 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long l, grib_arguments* c) { grib_accessor_g2grid* self = (grib_accessor_g2grid*)a; + grib_handle* hand = grib_handle_of_accessor(a); int n = 0; - self->latitude_first = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->longitude_first = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->latitude_last = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->longitude_last = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->i_increment = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->j_increment = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->basic_angle = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->sub_division = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); + self->latitude_first = grib_arguments_get_name(hand,c,n++); + self->longitude_first = grib_arguments_get_name(hand,c,n++); + self->latitude_last = grib_arguments_get_name(hand,c,n++); + self->longitude_last = grib_arguments_get_name(hand,c,n++); + self->i_increment = grib_arguments_get_name(hand,c,n++); + self->j_increment = grib_arguments_get_name(hand,c,n++); + self->basic_angle = grib_arguments_get_name(hand,c,n++); + self->sub_division = grib_arguments_get_name(hand,c,n++); a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC | @@ -181,6 +182,7 @@ static int value_count(grib_accessor* a,long* count) static int unpack_double(grib_accessor* a, double* val, size_t *len) { grib_accessor_g2grid* self = (grib_accessor_g2grid*)a; + grib_handle* hand = grib_handle_of_accessor(a); int ret = 0; long basic_angle = 0; @@ -194,10 +196,10 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) return ret; } - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->basic_angle,&basic_angle)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(hand, self->basic_angle,&basic_angle)) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_division,&sub_division)) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(hand, self->sub_division,&sub_division)) != GRIB_SUCCESS) return ret; @@ -208,27 +210,27 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) basic_angle = 1; n = 0; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->latitude_first,&v[n++])) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(hand, self->latitude_first,&v[n++])) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->longitude_first,&v[n++])) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(hand, self->longitude_first,&v[n++])) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->latitude_last,&v[n++])) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(hand, self->latitude_last,&v[n++])) != GRIB_SUCCESS) return ret; - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->longitude_last,&v[n++])) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(hand, self->longitude_last,&v[n++])) != GRIB_SUCCESS) return ret; if(!self->i_increment) v[n++] = GRIB_MISSING_LONG; else - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->i_increment,&v[n++])) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(hand, self->i_increment,&v[n++])) != GRIB_SUCCESS) return ret; if(!self->j_increment) v[n++] = GRIB_MISSING_LONG; else if(self->j_increment) - if((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->j_increment,&v[n++])) != GRIB_SUCCESS) + if((ret = grib_get_long_internal(hand, self->j_increment,&v[n++])) != GRIB_SUCCESS) return ret; for(i = 0 ; i < n ; i++) @@ -314,6 +316,7 @@ static int trial(const double* val,long v[6],long* basic_angle,long* sub_divisio static int pack_double(grib_accessor* a, const double* val, size_t *len) { grib_accessor_g2grid* self = (grib_accessor_g2grid*)a; + grib_handle* hand = grib_handle_of_accessor(a); int ret; long v[6]; int n; @@ -334,7 +337,6 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) } else if(trial(val,v,&basic_angle,&sub_division)) { - } else { @@ -351,33 +353,33 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) sub_division = GRIB_MISSING_LONG; } - if((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->basic_angle,basic_angle)) != GRIB_SUCCESS) + if((ret = grib_set_long_internal(hand, self->basic_angle,basic_angle)) != GRIB_SUCCESS) return ret; - if((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->sub_division,sub_division)) != GRIB_SUCCESS) + if((ret = grib_set_long_internal(hand, self->sub_division,sub_division)) != GRIB_SUCCESS) return ret; n = 0; - if((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->latitude_first,v[n++])) != GRIB_SUCCESS) + if((ret = grib_set_long_internal(hand, self->latitude_first,v[n++])) != GRIB_SUCCESS) return ret; - if((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->longitude_first,v[n++])) != GRIB_SUCCESS) + if((ret = grib_set_long_internal(hand, self->longitude_first,v[n++])) != GRIB_SUCCESS) return ret; - if((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->latitude_last,v[n++])) != GRIB_SUCCESS) + if((ret = grib_set_long_internal(hand, self->latitude_last,v[n++])) != GRIB_SUCCESS) return ret; - if((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->longitude_last,v[n++])) != GRIB_SUCCESS) + if((ret = grib_set_long_internal(hand, self->longitude_last,v[n++])) != GRIB_SUCCESS) return ret; if(!self->i_increment) n++; else - if((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->i_increment,v[n++])) != GRIB_SUCCESS) + if((ret = grib_set_long_internal(hand, self->i_increment,v[n++])) != GRIB_SUCCESS) return ret; if(!self->j_increment) n++; else - if((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->j_increment,v[n++])) != GRIB_SUCCESS) + if((ret = grib_set_long_internal(hand, self->j_increment,v[n++])) != GRIB_SUCCESS) return ret; return GRIB_SUCCESS; diff --git a/src/grib_accessor_class_validity_date.c b/src/grib_accessor_class_validity_date.c index 697fe8c3e..a900594c7 100644 --- a/src/grib_accessor_class_validity_date.c +++ b/src/grib_accessor_class_validity_date.c @@ -178,15 +178,16 @@ static long convert_to_minutes(long step, long stepUnits) static void init(grib_accessor* a,const long l, grib_arguments* c) { grib_accessor_validity_date* self = (grib_accessor_validity_date*)a; + grib_handle* hand = grib_handle_of_accessor(a); int n = 0; - self->date = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->time = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->step = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->stepUnits = 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->date = grib_arguments_get_name(hand,c,n++); + self->time = grib_arguments_get_name(hand,c,n++); + self->step = grib_arguments_get_name(hand,c,n++); + self->stepUnits = 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++); a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } @@ -199,6 +200,7 @@ static void dump(grib_accessor* a, grib_dumper* dumper) static int unpack_long(grib_accessor* a, long* val, size_t *len) { grib_accessor_validity_date* self = (grib_accessor_validity_date*)a; + grib_handle* hand = grib_handle_of_accessor(a); int ret=0; long date = 0; long time = 0; @@ -208,22 +210,22 @@ static int unpack_long(grib_accessor* a, long* val, size_t *len) if (self->year) { long year,month,day; - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->year,&year))!=GRIB_SUCCESS) return ret; - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->month,&month))!=GRIB_SUCCESS) return ret; - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->day,&day))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->year,&year))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->month,&month))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->day,&day))!=GRIB_SUCCESS) return ret; *val=year*10000+month*100+day; return GRIB_SUCCESS; } - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->date,&date))!=GRIB_SUCCESS) return ret; - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->time,&time))!=GRIB_SUCCESS) return ret; - if ((ret=grib_get_long(grib_handle_of_accessor(a), self->step,&step))!=GRIB_SUCCESS) { - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), "endStep",&step))!=GRIB_SUCCESS) { + if ((ret=grib_get_long_internal(hand, self->date,&date))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->time,&time))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long(hand, self->step,&step))!=GRIB_SUCCESS) { + if ((ret=grib_get_long_internal(hand, "endStep",&step))!=GRIB_SUCCESS) { return ret; /* See ECC-817 */ } } if (self->stepUnits) { - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->stepUnits,&stepUnits))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->stepUnits,&stepUnits))!=GRIB_SUCCESS) return ret; step_mins = convert_to_minutes(step, stepUnits); } diff --git a/src/grib_accessor_class_validity_time.c b/src/grib_accessor_class_validity_time.c index 0636cd058..f38416bd2 100644 --- a/src/grib_accessor_class_validity_time.c +++ b/src/grib_accessor_class_validity_time.c @@ -176,14 +176,15 @@ static long convert_to_minutes(long step, long stepUnits) static void init(grib_accessor* a,const long l, grib_arguments* c) { grib_accessor_validity_time* self = (grib_accessor_validity_time*)a; + grib_handle* hand = grib_handle_of_accessor(a); int n = 0; - self->date = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->time = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->step = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->stepUnits = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->hours = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - self->minutes = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); + self->date = grib_arguments_get_name(hand,c,n++); + self->time = grib_arguments_get_name(hand,c,n++); + self->step = grib_arguments_get_name(hand,c,n++); + self->stepUnits = grib_arguments_get_name(hand,c,n++); + self->hours = grib_arguments_get_name(hand,c,n++); + self->minutes = grib_arguments_get_name(hand,c,n++); a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } @@ -196,6 +197,7 @@ static void dump(grib_accessor* a, grib_dumper* dumper) static int unpack_long(grib_accessor* a, long* val, size_t *len) { grib_accessor_validity_time* self = (grib_accessor_validity_time*)a; + grib_handle* hand = grib_handle_of_accessor(a); int ret=0; long date = 0; long time = 0; @@ -204,22 +206,22 @@ static int unpack_long(grib_accessor* a, long* val, size_t *len) long hours = 0, minutes=0, step_mins=0, tmp, tmp_hrs, tmp_mins; if (self->hours) { - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->hours,&hours))!=GRIB_SUCCESS) return ret; - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->minutes,&minutes))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->hours,&hours))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->minutes,&minutes))!=GRIB_SUCCESS) return ret; *val=hours*100+minutes; return GRIB_SUCCESS; } - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->date,&date))!=GRIB_SUCCESS) return ret; - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->time,&time))!=GRIB_SUCCESS) return ret; - if ((ret=grib_get_long(grib_handle_of_accessor(a), self->step,&step))!=GRIB_SUCCESS) { - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), "endStep",&step))!=GRIB_SUCCESS) { + if ((ret=grib_get_long_internal(hand, self->date,&date))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->time,&time))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long(hand, self->step,&step))!=GRIB_SUCCESS) { + if ((ret=grib_get_long_internal(hand, "endStep",&step))!=GRIB_SUCCESS) { return ret; /* See ECC-817 */ } } /* Seconds will always be zero. So convert to minutes */ if (self->stepUnits) { - if ((ret=grib_get_long_internal(grib_handle_of_accessor(a), self->stepUnits,&stepUnits))!=GRIB_SUCCESS) return ret; + if ((ret=grib_get_long_internal(hand, self->stepUnits,&stepUnits))!=GRIB_SUCCESS) return ret; step_mins = convert_to_minutes(step, stepUnits); }