From 4bed297a442d550807e1ea73e432ce6953eb4175 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Fri, 17 Nov 2023 12:14:50 -0700 Subject: [PATCH] locale.c: Simplify some localeconv() code The previous commits have allowed this code to determine by looking at the position of a bit in a mask what is going on, and so the code that used to be there to cope with not having that can be removed. --- locale.c | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/locale.c b/locale.c index 2f0b2e7f653c..45fa5f87760e 100644 --- a/locale.c +++ b/locale.c @@ -5859,39 +5859,17 @@ S_populate_hash_from_localeconv(pTHX_ HV * hv, /* Finally, do the actual localeconv */ const char *lcbuf_as_string = (const char *) localeconv(); - /* Fill in the string fields of the HV* */ - for (unsigned int i = 0; i < 2; i++) { + PERL_UINT_FAST8_T working_mask = which_mask; + while (working_mask) { - /* One iteration is only for the numeric string fields. Skip these - * unless we are compiled to care about those fields and the input - * parameters indicate we want their values */ - if ( i == NUMERIC_OFFSET + /* Get the bit position of the next lowest set bit. That is the + * index into the 'strings' array of the category we use in this loop + * iteration. Turn the bit off so we don't work on this category + * again in this function call. */ + const PERL_UINT_FAST8_T i = lsbit_pos(working_mask); + working_mask &= ~ (1 << i); -# ifdef USE_LOCALE_NUMERIC - - && (which_mask & OFFSET_TO_BIT(NUMERIC_OFFSET)) == 0 - -# endif - - ) { - continue; - } - - /* The other iteration is only for the monetary string fields. Again - * skip it unless we want those values */ - if ( i == MONETARY_OFFSET - -# ifdef USE_LOCALE_MONETARY - - && (which_mask & OFFSET_TO_BIT(MONETARY_OFFSET)) == 0 - -# endif - ) { - - continue; - } - - /* For each field for the given category ... */ + /* For each string field for the given category ... */ const lconv_offset_t * category_strings = strings[i]; while (category_strings->name) {