Performance: Call grib_handle_of_accessor once

This commit is contained in:
shahramn 2024-10-20 12:47:34 +01:00
parent f72f8bc5b8
commit 9736f663dc
27 changed files with 70 additions and 84 deletions

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -94,6 +94,8 @@ int grib_accessor_data_jpeg2000_packing_t::unpack_float(float* val, size_t* len)
int grib_accessor_data_jpeg2000_packing_t::unpack_double(double* val, size_t* len)
{
int err = GRIB_SUCCESS;
grib_handle* hand = grib_handle_of_accessor(this);
size_t i = 0;
size_t buflen = byte_count();
double bscale = 0;
@ -116,18 +118,18 @@ int grib_accessor_data_jpeg2000_packing_t::unpack_double(double* val, size_t* le
return err;
if (units_factor_)
grib_get_double_internal(grib_handle_of_accessor(this), units_factor_, &units_factor);
grib_get_double_internal(hand, units_factor_, &units_factor);
if (units_bias_)
grib_get_double_internal(grib_handle_of_accessor(this), units_bias_, &units_bias);
grib_get_double_internal(hand, units_bias_, &units_bias);
if ((err = grib_get_long_internal(grib_handle_of_accessor(this), bits_per_value_, &bits_per_value)) != GRIB_SUCCESS)
if ((err = grib_get_long_internal(hand, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS)
return err;
if ((err = grib_get_double_internal(grib_handle_of_accessor(this), reference_value_, &reference_value)) != GRIB_SUCCESS)
if ((err = grib_get_double_internal(hand, reference_value_, &reference_value)) != GRIB_SUCCESS)
return err;
if ((err = grib_get_long_internal(grib_handle_of_accessor(this), binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS)
if ((err = grib_get_long_internal(hand, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS)
return err;
if ((err = grib_get_long_internal(grib_handle_of_accessor(this), decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS)
if ((err = grib_get_long_internal(hand, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS)
return err;
dirty_ = 0;
@ -194,7 +196,6 @@ int grib_accessor_data_jpeg2000_packing_t::pack_double(const double* cval, size_
{
size_t n_vals = *len;
int err = 0;
int i;
double reference_value = 0;
long binary_scale_factor = 0;
long bits_per_value = 0;
@ -237,14 +238,14 @@ int grib_accessor_data_jpeg2000_packing_t::pack_double(const double* cval, size_
if (units_factor != 1.0) {
if (units_bias != 0.0)
for (i = 0; i < n_vals; i++)
for (size_t i = 0; i < n_vals; i++)
val[i] = val[i] * units_factor + units_bias;
else
for (i = 0; i < n_vals; i++)
for (size_t i = 0; i < n_vals; i++)
val[i] *= units_factor;
}
else if (units_bias != 0.0)
for (i = 0; i < n_vals; i++)
for (size_t i = 0; i < n_vals; i++)
val[i] += units_bias;
ret = grib_accessor_data_simple_packing_t::pack_double(val, len);

View File

@ -16,15 +16,16 @@ grib_accessor* grib_accessor_evaluate = &_grib_accessor_evaluate;
void grib_accessor_evaluate_t::init(const long l, grib_arguments* c)
{
grib_accessor_long_t::init(l, c);
arg_ = c;
arg_ = c; // the expression to be evaluated
flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY;
}
int grib_accessor_evaluate_t::unpack_long(long* val, size_t* len)
{
grib_expression* e = grib_arguments_get_expression(grib_handle_of_accessor(this), arg_, 0);
grib_handle* h = grib_handle_of_accessor(this);
grib_expression* e = grib_arguments_get_expression(h, arg_, 0);
int ret = grib_expression_evaluate_long(grib_handle_of_accessor(this), e, val);
int ret = grib_expression_evaluate_long(h, e, val);
*len = 1;
return ret;

View File

@ -22,5 +22,5 @@ public:
void init(const long, grib_arguments*) override;
protected:
grib_arguments* arg_;
grib_arguments* arg_; // expression to be evaluated
};

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -527,13 +527,13 @@ int grib_accessor_g2end_step_t::pack_long_(const long end_step_value, const long
time_range_opt = eccodes::Step{ time_range.value<long>(eccodes::Unit{ force_step_units }), eccodes::Unit{ force_step_units } };
}
if ((err = grib_set_long_internal(grib_handle_of_accessor(this), time_range_value_, time_range_opt.value<long>())) != GRIB_SUCCESS)
if ((err = grib_set_long_internal(h, time_range_value_, time_range_opt.value<long>())) != GRIB_SUCCESS)
return err;
if ((err = grib_set_long_internal(grib_handle_of_accessor(this), time_range_unit_, time_range_opt.unit().value<long>())) != GRIB_SUCCESS)
if ((err = grib_set_long_internal(h, time_range_unit_, time_range_opt.unit().value<long>())) != GRIB_SUCCESS)
return err;
if ((err = grib_set_long_internal(grib_handle_of_accessor(this), forecast_time_value_key, forecast_time_opt.value<long>())) != GRIB_SUCCESS)
if ((err = grib_set_long_internal(h, forecast_time_value_key, forecast_time_opt.value<long>())) != GRIB_SUCCESS)
return err;
if ((err = grib_set_long_internal(grib_handle_of_accessor(this), forecast_time_unit_key, forecast_time_opt.unit().value<long>())) != GRIB_SUCCESS)
if ((err = grib_set_long_internal(h, forecast_time_unit_key, forecast_time_opt.unit().value<long>())) != GRIB_SUCCESS)
return err;
return GRIB_SUCCESS;

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*

View File

@ -17,11 +17,12 @@ void grib_accessor_julian_day_t::init(const long l, grib_arguments* c)
{
grib_accessor_double_t::init(l, c);
int n = 0;
grib_handle* h = grib_handle_of_accessor(this);
date_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++);
hour_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++);
minute_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++);
second_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++);
date_ = grib_arguments_get_name(h, c, n++);
hour_ = grib_arguments_get_name(h, c, n++);
minute_ = grib_arguments_get_name(h, c, n++);
second_ = grib_arguments_get_name(h, c, n++);
length_ = 0;
}
@ -39,29 +40,27 @@ int grib_accessor_julian_day_t::pack_long(const long* val, size_t* len)
int grib_accessor_julian_day_t::pack_double(const double* val, size_t* len)
{
int ret = 0;
long hour = 0;
long minute = 0;
long second = 0;
long date = 0;
long year, month, day;
int ret = GRIB_SUCCESS;
long hour = 0, minute = 0, second = 0;
long year = 0, month = 0, day = 0;
grib_handle* h = grib_handle_of_accessor(this);
ret = grib_julian_to_datetime(*val, &year, &month, &day, &hour, &minute, &second);
if (ret != 0)
return ret;
date = year * 10000 + month * 100 + day;
long date = year * 10000 + month * 100 + day;
ret = grib_set_long_internal(grib_handle_of_accessor(this), date_, date);
ret = grib_set_long_internal(h, date_, date);
if (ret != 0)
return ret;
ret = grib_set_long_internal(grib_handle_of_accessor(this), hour_, hour);
ret = grib_set_long_internal(h, hour_, hour);
if (ret != 0)
return ret;
ret = grib_set_long_internal(grib_handle_of_accessor(this), minute_, minute);
ret = grib_set_long_internal(h, minute_, minute);
if (ret != 0)
return ret;
ret = grib_set_long_internal(grib_handle_of_accessor(this), second_, second);
ret = grib_set_long_internal(h, second_, second);
return ret;
}
@ -82,17 +81,18 @@ int grib_accessor_julian_day_t::unpack_double(double* val, size_t* len)
int ret = 0;
long date, hour, minute, second;
long year, month, day;
grib_handle* h = grib_handle_of_accessor(this);
ret = grib_get_long_internal(grib_handle_of_accessor(this), date_, &date);
ret = grib_get_long_internal(h, date_, &date);
if (ret != GRIB_SUCCESS)
return ret;
ret = grib_get_long_internal(grib_handle_of_accessor(this), hour_, &hour);
ret = grib_get_long_internal(h, hour_, &hour);
if (ret != GRIB_SUCCESS)
return ret;
ret = grib_get_long_internal(grib_handle_of_accessor(this), minute_, &minute);
ret = grib_get_long_internal(h, minute_, &minute);
if (ret != GRIB_SUCCESS)
return ret;
ret = grib_get_long_internal(grib_handle_of_accessor(this), second_, &second);
ret = grib_get_long_internal(h, second_, &second);
if (ret != GRIB_SUCCESS)
return ret;

View File

@ -16,12 +16,14 @@ grib_accessor* grib_accessor_number_of_coded_values = &_grib_accessor_number_of_
void grib_accessor_number_of_coded_values_t::init(const long l, grib_arguments* c)
{
grib_accessor_long_t::init(l, c);
grib_handle* h = grib_handle_of_accessor(this);
int n = 0;
bitsPerValue_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++);
offsetBeforeData_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++);
offsetAfterData_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++);
unusedBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++);
numberOfValues_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++);
bitsPerValue_ = grib_arguments_get_name(h, c, n++);
offsetBeforeData_ = grib_arguments_get_name(h, c, n++);
offsetAfterData_ = grib_arguments_get_name(h, c, n++);
unusedBits_ = grib_arguments_get_name(h, c, n++);
numberOfValues_ = grib_arguments_get_name(h, c, n++);
flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY;
flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION;
length_ = 0;
@ -30,29 +32,30 @@ void grib_accessor_number_of_coded_values_t::init(const long l, grib_arguments*
int grib_accessor_number_of_coded_values_t::unpack_long(long* val, size_t* len)
{
int ret = GRIB_SUCCESS;
long bpv = 0;
long offsetBeforeData = 0, offsetAfterData = 0, unusedBits = 0, numberOfValues;
long bpv = 0, offsetBeforeData = 0, offsetAfterData = 0, unusedBits = 0, numberOfValues;
grib_handle* h = grib_handle_of_accessor(this);
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), bitsPerValue_, &bpv)) != GRIB_SUCCESS)
if ((ret = grib_get_long_internal(h, bitsPerValue_, &bpv)) != GRIB_SUCCESS)
return ret;
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetBeforeData_, &offsetBeforeData)) != GRIB_SUCCESS)
if ((ret = grib_get_long_internal(h, offsetBeforeData_, &offsetBeforeData)) != GRIB_SUCCESS)
return ret;
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetAfterData_, &offsetAfterData)) != GRIB_SUCCESS)
if ((ret = grib_get_long_internal(h, offsetAfterData_, &offsetAfterData)) != GRIB_SUCCESS)
return ret;
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), unusedBits_, &unusedBits)) != GRIB_SUCCESS)
if ((ret = grib_get_long_internal(h, unusedBits_, &unusedBits)) != GRIB_SUCCESS)
return ret;
if (bpv != 0) {
grib_context_log(context_, GRIB_LOG_DEBUG, "grib_accessor_number_of_coded_values_t: offsetAfterData=%ld offsetBeforeData=%ld unusedBits=%ld bpv=%ld\n",
grib_context_log(context_, GRIB_LOG_DEBUG,
"grib_accessor_number_of_coded_values_t: offsetAfterData=%ld offsetBeforeData=%ld unusedBits=%ld bpv=%ld",
offsetAfterData, offsetBeforeData, unusedBits, bpv);
DEBUG_ASSERT(offsetAfterData > offsetBeforeData);
*val = ((offsetAfterData - offsetBeforeData) * 8 - unusedBits) / bpv;
}
else {
if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfValues_, &numberOfValues)) != GRIB_SUCCESS)
if ((ret = grib_get_long_internal(h, numberOfValues_, &numberOfValues)) != GRIB_SUCCESS)
return ret;
*val = numberOfValues;

View File

@ -17,12 +17,13 @@ void grib_accessor_statistics_spectral_t::init(const long l, grib_arguments* c)
{
grib_accessor_abstract_vector_t::init(l, c);
int n = 0;
grib_handle* h = grib_handle_of_accessor(this);
values_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++);
J_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++);
K_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++);
M_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++);
JS_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++);
values_ = grib_arguments_get_name(h, c, n++);
J_ = grib_arguments_get_name(h, c, n++);
K_ = grib_arguments_get_name(h, c, n++);
M_ = grib_arguments_get_name(h, c, n++);
JS_ = grib_arguments_get_name(h, c, n++);
flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY;
flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION;
@ -53,13 +54,13 @@ int grib_accessor_statistics_spectral_t::unpack_double(double* val, size_t* len)
if ((ret = grib_get_size(h, values_, &size)) != GRIB_SUCCESS)
return ret;
if ((ret = grib_get_long(grib_handle_of_accessor(this), J_, &J)) != GRIB_SUCCESS)
if ((ret = grib_get_long(h, J_, &J)) != GRIB_SUCCESS)
return ret;
if ((ret = grib_get_long(grib_handle_of_accessor(this), K_, &K)) != GRIB_SUCCESS)
if ((ret = grib_get_long(h, K_, &K)) != GRIB_SUCCESS)
return ret;
if ((ret = grib_get_long(grib_handle_of_accessor(this), M_, &M)) != GRIB_SUCCESS)
if ((ret = grib_get_long(h, M_, &M)) != GRIB_SUCCESS)
return ret;
if (J != M || M != K)
@ -114,7 +115,7 @@ int grib_accessor_statistics_spectral_t::unpack_double(double* val, size_t* len)
int grib_accessor_statistics_spectral_t::value_count(long* count)
{
*count = number_of_elements_;
return 0;
return GRIB_SUCCESS;
}
void grib_accessor_statistics_spectral_t::destroy(grib_context* c)