From f0b68e4b157da02e4fcbda6ddd6634bfac32d847 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 8 May 2024 13:05:36 +0100 Subject: [PATCH] ECC-1820: Accessor hash --- src/grib_accessor_classes_hash.cc | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/grib_accessor_classes_hash.cc b/src/grib_accessor_classes_hash.cc index 178ed937b..5617c9456 100644 --- a/src/grib_accessor_classes_hash.cc +++ b/src/grib_accessor_classes_hash.cc @@ -51,8 +51,7 @@ struct accessor_class_hash { const char *name; grib_accessor_class **cclass;}; #endif #endif -static unsigned int -grib_accessor_classes_get_id (const char *str, size_t len) +static unsigned int grib_accessor_classes_get_id (const char *str, size_t len) { static const unsigned short asso_values[] = { @@ -622,20 +621,19 @@ static const struct accessor_class_hash classes[] = {"g1verificationdate", &grib_accessor_class_g1verificationdate} }; -const struct accessor_class_hash * -grib_accessor_classes_hash (const char *str, size_t len) -{ - if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) +static const struct accessor_class_hash* grib_accessor_classes_hash(const char *str, size_t len) { unsigned int key = grib_accessor_classes_get_id (str, len); - if (key <= MAX_HASH_VALUE) +#ifdef DEBUG { - const char *s = classes[key].name; - - if (*str == *s && !strcmp (str + 1, s + 1)) - return &classes[key]; - } + const char *s; + Assert( len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH ); + Assert( key <= MAX_HASH_VALUE ); + s = classes[key].name; + Assert( *str == *s && strcmp(str + 1, s + 1)==0 ); } - return 0; +#endif + + return &classes[key]; }