Skip to content

Commit

Permalink
locale.c: Simplify some localeconv() code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
khwilliamson committed Nov 22, 2023
1 parent b8e7c19 commit 4bed297
Showing 1 changed file with 9 additions and 31 deletions.
40 changes: 9 additions & 31 deletions locale.c
Expand Up @@ -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) {

Expand Down

0 comments on commit 4bed297

Please sign in to comment.