Skip to content

Commit

Permalink
locale.c: Special case some C locale values
Browse files Browse the repository at this point in the history
On Windows and MingW, some of this code can be frequently called, and
often with the C locale in effect.  Normally localeconv() is called to
fill in these values, but that is expensive in part because of a bunch
of setlocale() calls, some of which are extra, needed because of bugs in
the Windows libc.  We can short circuit that for the common C locale
case, as the values are known at compile time.
  • Loading branch information
khwilliamson committed Nov 17, 2023
1 parent 234678c commit 426a8c5
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions locale.c
Expand Up @@ -5531,13 +5531,15 @@ S_my_localeconv(pTHX_ const int item)

/* End of all the initialization of data structures. Now for actual code.
*
* Without nl_langinfo(), the call to my_localeconv() could be for just one
* of the following 3 items to emulate nl_langinfo(). This is compiled
* only when using perl_langinfo.h, which we control, and it has been
* constructed so that no item is numbered 0.
* Without nl_langinfo(), the call to my_localeconv() could be for all of
* the localeconv() items or for just one of the following 3 items to
* emulate nl_langinfo(). This is compiled only when using
* perl_langinfo.h, which we control, and it has been constructed so that
* no item is numbered 0.
*
* For each, set up the appropriate parameters for the call below to
* S_populate_hash_from_localeconv() */
* For each individual item, either return the known value if the current
* locale is "C", or set up the appropriate parameters for the call below
* to the populate function */
if (item != 0) {
switch (item) {
default:
Expand All @@ -5548,10 +5550,20 @@ S_my_localeconv(pTHX_ const int item)
# ifdef USE_LOCALE_NUMERIC

case RADIXCHAR:
if (isNAME_C_OR_POSIX(PL_numeric_name)) {
(void) hv_stores(hv, DECIMAL_POINT_LITERAL, newSVpvs("."));
return hv;
}

strings[NUMERIC_OFFSET] = DECIMAL_POINT_ADDRESS;
goto numeric_common;

case THOUSEP:
if (isNAME_C_OR_POSIX(PL_numeric_name)) {
(void) hv_stores(hv, THOUSANDS_SEP_LITERAL, newSVpvs(""));
return hv;
}

strings[NUMERIC_OFFSET] = thousands_sep_string;

numeric_common:
Expand All @@ -5563,10 +5575,16 @@ S_my_localeconv(pTHX_ const int item)
# endif
# ifdef USE_LOCALE_MONETARY

case CRNCYSTR:
/* This item needs the values for both the currency symbol, and
* another one used to construct the nl_langino()-compatible
* return. */
case CRNCYSTR: /* This item needs the values for both the currency
symbol, and another one used to construct the
nl_langino()-compatible return. */

if (isNAME_C_OR_POSIX(PL_numeric_name)) {
(void) hv_stores(hv, CURRENCY_SYMBOL_LITERAL, newSVpvs(""));
(void) hv_stores(hv, P_CS_PRECEDES_LITERAL, newSViv(-1));
return hv;
}

strings[MONETARY_OFFSET] = CURRENCY_SYMBOL_ADDRESS;
integers = P_CS_PRECEDES_ADDRESS;

Expand Down

0 comments on commit 426a8c5

Please sign in to comment.