From 313867fa8bd77b9c34397cf13cdf3829885b0d5c Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 27 Dec 2022 16:16:56 +0000 Subject: [PATCH] BUFR dumpers: No need for inlined strcmp --- src/grib_dumper_class_bufr_decode_C.c | 21 ++++----------------- src/grib_dumper_class_bufr_decode_filter.c | 21 ++++----------------- src/grib_dumper_class_bufr_decode_fortran.c | 21 ++++----------------- src/grib_dumper_class_bufr_decode_python.c | 21 ++++----------------- src/grib_dumper_class_bufr_encode_C.c | 21 ++++----------------- src/grib_dumper_class_bufr_encode_filter.c | 21 ++++----------------- src/grib_dumper_class_bufr_encode_fortran.c | 21 ++++----------------- src/grib_dumper_class_bufr_encode_python.c | 21 ++++----------------- src/grib_dumper_class_bufr_simple.c | 21 ++++----------------- src/grib_dumper_class_json.c | 21 ++++----------------- 10 files changed, 40 insertions(+), 170 deletions(-) diff --git a/src/grib_dumper_class_bufr_decode_C.c b/src/grib_dumper_class_bufr_decode_C.c index 5c720d3ee..f02070d8e 100644 --- a/src/grib_dumper_class_bufr_decode_C.c +++ b/src/grib_dumper_class_bufr_decode_C.c @@ -95,19 +95,6 @@ grib_dumper_class* grib_dumper_class_bufr_decode_C = &_grib_dumper_class_bufr_de /* END_CLASS_IMP */ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix); -/* Note: A fast cut-down version of strcmp which does NOT return -1 */ -/* 0 means input strings are equal and 1 means not equal */ -GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) -{ - if (*a != *b) - return 1; - while ((*a != 0 && *b != 0) && *(a) == *(b)) { - a++; - b++; - } - return (*a == 0 && *b == 0) ? 0 : 1; -} - static int depth = 0; static void init_class(grib_dumper_class* c) {} @@ -622,9 +609,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key) static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_decode_C* self = (grib_dumper_bufr_decode_C*)d; - if (!grib_inline_strcmp(a->name, "BUFR") || - !grib_inline_strcmp(a->name, "GRIB") || - !grib_inline_strcmp(a->name, "META")) { + if (strcmp(a->name, "BUFR")==0 || + strcmp(a->name, "GRIB")==0 || + strcmp(a->name, "META")==0) { grib_handle* h = grib_handle_of_accessor(a); depth = 2; self->empty = 1; @@ -638,7 +625,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dump_accessors_block(d, block); depth -= 2; } - else if (!grib_inline_strcmp(a->name, "groupNumber")) { + else if (strcmp(a->name, "groupNumber")==0) { if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->empty = 1; diff --git a/src/grib_dumper_class_bufr_decode_filter.c b/src/grib_dumper_class_bufr_decode_filter.c index febc76237..1c7434cdb 100644 --- a/src/grib_dumper_class_bufr_decode_filter.c +++ b/src/grib_dumper_class_bufr_decode_filter.c @@ -94,19 +94,6 @@ grib_dumper_class* grib_dumper_class_bufr_decode_filter = &_grib_dumper_class_bu /* END_CLASS_IMP */ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix); -/* Note: A fast cut-down version of strcmp which does NOT return -1 */ -/* 0 means input strings are equal and 1 means not equal */ -GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) -{ - if (*a != *b) - return 1; - while ((*a != 0 && *b != 0) && *(a) == *(b)) { - a++; - b++; - } - return (*a == 0 && *b == 0) ? 0 : 1; -} - static int depth = 0; static void init_class(grib_dumper_class* c) {} @@ -533,9 +520,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key) static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_decode_filter* self = (grib_dumper_bufr_decode_filter*)d; - if (!grib_inline_strcmp(a->name, "BUFR") || - !grib_inline_strcmp(a->name, "GRIB") || - !grib_inline_strcmp(a->name, "META")) { + if (strcmp(a->name, "BUFR")==0 || + strcmp(a->name, "GRIB")==0 || + strcmp(a->name, "META")==0) { grib_handle* h = grib_handle_of_accessor(a); depth = 2; self->begin = 1; @@ -550,7 +537,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dump_accessors_block(d, block); depth -= 2; } - else if (!grib_inline_strcmp(a->name, "groupNumber")) { + else if (strcmp(a->name, "groupNumber")==0) { if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->begin = 1; diff --git a/src/grib_dumper_class_bufr_decode_fortran.c b/src/grib_dumper_class_bufr_decode_fortran.c index 33728fd5a..9a3871c40 100644 --- a/src/grib_dumper_class_bufr_decode_fortran.c +++ b/src/grib_dumper_class_bufr_decode_fortran.c @@ -95,19 +95,6 @@ grib_dumper_class* grib_dumper_class_bufr_decode_fortran = &_grib_dumper_class_b /* END_CLASS_IMP */ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix); -/* Note: A fast cut-down version of strcmp which does NOT return -1 */ -/* 0 means input strings are equal and 1 means not equal */ -GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) -{ - if (*a != *b) - return 1; - while ((*a != 0 && *b != 0) && *(a) == *(b)) { - a++; - b++; - } - return (*a == 0 && *b == 0) ? 0 : 1; -} - static int depth = 0; static void init_class(grib_dumper_class* c) {} @@ -563,9 +550,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key) static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_decode_fortran* self = (grib_dumper_bufr_decode_fortran*)d; - if (!grib_inline_strcmp(a->name, "BUFR") || - !grib_inline_strcmp(a->name, "GRIB") || - !grib_inline_strcmp(a->name, "META")) { + if (strcmp(a->name, "BUFR")==0 || + strcmp(a->name, "GRIB")==0 || + strcmp(a->name, "META")==0) { grib_handle* h = grib_handle_of_accessor(a); depth = 2; self->empty = 1; @@ -579,7 +566,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dump_accessors_block(d, block); depth -= 2; } - else if (!grib_inline_strcmp(a->name, "groupNumber")) { + else if (strcmp(a->name, "groupNumber")==0) { if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->empty = 1; diff --git a/src/grib_dumper_class_bufr_decode_python.c b/src/grib_dumper_class_bufr_decode_python.c index 73295b5f0..3b6cffba0 100644 --- a/src/grib_dumper_class_bufr_decode_python.c +++ b/src/grib_dumper_class_bufr_decode_python.c @@ -95,19 +95,6 @@ grib_dumper_class* grib_dumper_class_bufr_decode_python = &_grib_dumper_class_bu /* END_CLASS_IMP */ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix); -/* Note: A fast cut-down version of strcmp which does NOT return -1 */ -/* 0 means input strings are equal and 1 means not equal */ -GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) -{ - if (*a != *b) - return 1; - while ((*a != 0 && *b != 0) && *(a) == *(b)) { - a++; - b++; - } - return (*a == 0 && *b == 0) ? 0 : 1; -} - static int depth = 0; static void init_class(grib_dumper_class* c) {} @@ -573,9 +560,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key) static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_decode_python* self = (grib_dumper_bufr_decode_python*)d; - if (!grib_inline_strcmp(a->name, "BUFR") || - !grib_inline_strcmp(a->name, "GRIB") || - !grib_inline_strcmp(a->name, "META")) { + if (strcmp(a->name, "BUFR")==0 || + strcmp(a->name, "GRIB")==0 || + strcmp(a->name, "META")==0) { grib_handle* h = grib_handle_of_accessor(a); depth = 2; self->empty = 1; @@ -589,7 +576,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dump_accessors_block(d, block); depth -= 2; } - else if (!grib_inline_strcmp(a->name, "groupNumber")) { + else if (strcmp(a->name, "groupNumber")==0) { if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->empty = 1; diff --git a/src/grib_dumper_class_bufr_encode_C.c b/src/grib_dumper_class_bufr_encode_C.c index 0d6df733c..5c915049f 100644 --- a/src/grib_dumper_class_bufr_encode_C.c +++ b/src/grib_dumper_class_bufr_encode_C.c @@ -95,19 +95,6 @@ grib_dumper_class* grib_dumper_class_bufr_encode_C = &_grib_dumper_class_bufr_en /* END_CLASS_IMP */ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix); -/* Note: A fast cut-down version of strcmp which does NOT return -1 */ -/* 0 means input strings are equal and 1 means not equal */ -GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) -{ - if (*a != *b) - return 1; - while ((*a != 0 && *b != 0) && *(a) == *(b)) { - a++; - b++; - } - return (*a == 0 && *b == 0) ? 0 : 1; -} - static int depth = 0; static void init_class(grib_dumper_class* c) {} @@ -795,9 +782,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_encode_C* self = (grib_dumper_bufr_encode_C*)d; - if (!grib_inline_strcmp(a->name, "BUFR") || - !grib_inline_strcmp(a->name, "GRIB") || - !grib_inline_strcmp(a->name, "META")) { + if (strcmp(a->name, "BUFR")==0 || + strcmp(a->name, "GRIB")==0 || + strcmp(a->name, "META")==0) { grib_handle* h = grib_handle_of_accessor(a); depth = 2; self->empty = 1; @@ -810,7 +797,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dump_accessors_block(d, block); depth -= 2; } - else if (!grib_inline_strcmp(a->name, "groupNumber")) { + else if (strcmp(a->name, "groupNumber")==0) { if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->empty = 1; diff --git a/src/grib_dumper_class_bufr_encode_filter.c b/src/grib_dumper_class_bufr_encode_filter.c index 3690ea9ec..de3db03ca 100644 --- a/src/grib_dumper_class_bufr_encode_filter.c +++ b/src/grib_dumper_class_bufr_encode_filter.c @@ -96,19 +96,6 @@ grib_dumper_class* grib_dumper_class_bufr_encode_filter = &_grib_dumper_class_bu /* END_CLASS_IMP */ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix); -/* Note: A fast cut-down version of strcmp which does NOT return -1 */ -/* 0 means input strings are equal and 1 means not equal */ -GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) -{ - if (*a != *b) - return 1; - while ((*a != 0 && *b != 0) && *(a) == *(b)) { - a++; - b++; - } - return (*a == 0 && *b == 0) ? 0 : 1; -} - static int depth = 0; static void init_class(grib_dumper_class* c) {} @@ -723,9 +710,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_encode_filter* self = (grib_dumper_bufr_encode_filter*)d; - if (!grib_inline_strcmp(a->name, "BUFR") || - !grib_inline_strcmp(a->name, "GRIB") || - !grib_inline_strcmp(a->name, "META")) { + if (strcmp(a->name, "BUFR")==0 || + strcmp(a->name, "GRIB")==0 || + strcmp(a->name, "META")==0) { grib_handle* h = grib_handle_of_accessor(a); depth = 2; self->begin = 1; @@ -739,7 +726,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dump_accessors_block(d, block); depth -= 2; } - else if (!grib_inline_strcmp(a->name, "groupNumber")) { + else if (strcmp(a->name, "groupNumber")==0) { if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->begin = 1; diff --git a/src/grib_dumper_class_bufr_encode_fortran.c b/src/grib_dumper_class_bufr_encode_fortran.c index 770b8f2a4..2c722a50c 100644 --- a/src/grib_dumper_class_bufr_encode_fortran.c +++ b/src/grib_dumper_class_bufr_encode_fortran.c @@ -96,19 +96,6 @@ grib_dumper_class* grib_dumper_class_bufr_encode_fortran = &_grib_dumper_class_b /* END_CLASS_IMP */ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix); -/* Note: A fast cut-down version of strcmp which does NOT return -1 */ -/* 0 means input strings are equal and 1 means not equal */ -GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) -{ - if (*a != *b) - return 1; - while ((*a != 0 && *b != 0) && *(a) == *(b)) { - a++; - b++; - } - return (*a == 0 && *b == 0) ? 0 : 1; -} - static int depth = 0; static void init_class(grib_dumper_class* c) {} @@ -841,9 +828,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d; - if (!grib_inline_strcmp(a->name, "BUFR") || - !grib_inline_strcmp(a->name, "GRIB") || - !grib_inline_strcmp(a->name, "META")) { + if (strcmp(a->name, "BUFR")==0 || + strcmp(a->name, "GRIB")==0 || + strcmp(a->name, "META")==0) { grib_handle* h = grib_handle_of_accessor(a); depth = 2; self->empty = 1; @@ -856,7 +843,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dump_accessors_block(d, block); depth -= 2; } - else if (!grib_inline_strcmp(a->name, "groupNumber")) { + else if (strcmp(a->name, "groupNumber")==0) { if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->empty = 1; diff --git a/src/grib_dumper_class_bufr_encode_python.c b/src/grib_dumper_class_bufr_encode_python.c index 8483408f9..f7344acdb 100644 --- a/src/grib_dumper_class_bufr_encode_python.c +++ b/src/grib_dumper_class_bufr_encode_python.c @@ -95,19 +95,6 @@ grib_dumper_class* grib_dumper_class_bufr_encode_python = &_grib_dumper_class_bu /* END_CLASS_IMP */ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix); -/* Note: A fast cut-down version of strcmp which does NOT return -1 */ -/* 0 means input strings are equal and 1 means not equal */ -GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) -{ - if (*a != *b) - return 1; - while ((*a != 0 && *b != 0) && *(a) == *(b)) { - a++; - b++; - } - return (*a == 0 && *b == 0) ? 0 : 1; -} - static int depth = 0; static void init_class(grib_dumper_class* c) {} @@ -783,9 +770,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_encode_python* self = (grib_dumper_bufr_encode_python*)d; - if (!grib_inline_strcmp(a->name, "BUFR") || - !grib_inline_strcmp(a->name, "GRIB") || - !grib_inline_strcmp(a->name, "META")) { + if (strcmp(a->name, "BUFR")==0 || + strcmp(a->name, "GRIB")==0 || + strcmp(a->name, "META")==0) { grib_handle* h = grib_handle_of_accessor(a); depth = 2; self->empty = 1; @@ -798,7 +785,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dump_accessors_block(d, block); depth -= 2; } - else if (!grib_inline_strcmp(a->name, "groupNumber")) { + else if (strcmp(a->name, "groupNumber")==0) { if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->empty = 1; diff --git a/src/grib_dumper_class_bufr_simple.c b/src/grib_dumper_class_bufr_simple.c index e4c4b2c51..2759c20f5 100644 --- a/src/grib_dumper_class_bufr_simple.c +++ b/src/grib_dumper_class_bufr_simple.c @@ -94,19 +94,6 @@ grib_dumper_class* grib_dumper_class_bufr_simple = &_grib_dumper_class_bufr_simp /* END_CLASS_IMP */ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix); -/* Note: A fast cut-down version of strcmp which does NOT return -1 */ -/* 0 means input strings are equal and 1 means not equal */ -GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) -{ - if (*a != *b) - return 1; - while ((*a != 0 && *b != 0) && *(a) == *(b)) { - a++; - b++; - } - return (*a == 0 && *b == 0) ? 0 : 1; -} - static void init_class(grib_dumper_class* c) {} static int init(grib_dumper* d) @@ -736,9 +723,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key) static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_simple* self = (grib_dumper_bufr_simple*)d; - if (!grib_inline_strcmp(a->name, "BUFR") || - !grib_inline_strcmp(a->name, "GRIB") || - !grib_inline_strcmp(a->name, "META")) { + if (strcmp(a->name, "BUFR")==0 || + strcmp(a->name, "GRIB")==0 || + strcmp(a->name, "META")==0) { int err = 0; grib_handle* h = grib_handle_of_accessor(a); self->empty = 1; @@ -753,7 +740,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso /*_dump_long_array(h,self->dumper.out,"inputOverriddenReferenceValues","inputOverriddenReferenceValues");*/ grib_dump_accessors_block(d, block); } - else if (!grib_inline_strcmp(a->name, "groupNumber")) { + else if (strcmp(a->name, "groupNumber")==0) { if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->empty = 1; diff --git a/src/grib_dumper_class_json.c b/src/grib_dumper_class_json.c index 020fc9d92..b0f43bd10 100644 --- a/src/grib_dumper_class_json.c +++ b/src/grib_dumper_class_json.c @@ -92,19 +92,6 @@ grib_dumper_class* grib_dumper_class_json = &_grib_dumper_class_json; /* END_CLASS_IMP */ static void dump_attributes(grib_dumper* d, grib_accessor* a); -/* Note: A fast cut-down version of strcmp which does NOT return -1 */ -/* 0 means input strings are equal and 1 means not equal */ -GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) -{ - if (*a != *b) - return 1; - while ((*a != 0 && *b != 0) && *(a) == *(b)) { - a++; - b++; - } - return (*a == 0 && *b == 0) ? 0 : 1; -} - static int depth = 0; static void init_class(grib_dumper_class* c) {} @@ -539,9 +526,9 @@ static void dump_label(grib_dumper* d, grib_accessor* a, const char* comment) static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_json* self = (grib_dumper_json*)d; - if (!grib_inline_strcmp(a->name, "BUFR") || - !grib_inline_strcmp(a->name, "GRIB") || - !grib_inline_strcmp(a->name, "META")) { + if (strcmp(a->name, "BUFR")==0 || + strcmp(a->name, "GRIB")==0 || + strcmp(a->name, "META")==0) { depth = 2; fprintf(self->dumper.out, "%-*s", depth, " "); fprintf(self->dumper.out, "[\n"); @@ -552,7 +539,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso depth -= 2; fprintf(self->dumper.out, "\n]\n"); } - else if (!grib_inline_strcmp(a->name, "groupNumber")) { + else if (strcmp(a->name, "groupNumber")==0) { if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; if (!self->empty)