From 7cf17f01a1acdde626566d9319532b9a125126f4 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Mon, 15 Feb 2021 19:46:57 -0700 Subject: [PATCH] locale.c: Make statics of repeated string constants These strings are (or soon will be) used in multiple places; so have just one definition for them. --- locale.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/locale.c b/locale.c index 0396444cf609..ba40bb2f1ad1 100644 --- a/locale.c +++ b/locale.c @@ -126,6 +126,11 @@ static int debug_initialization = 0; * the compiler warnings about comparing unlike signs */ #define STRLENs(s) (sizeof("" s "") - 1) +/* Default values come from the C locale */ +static const char C_codeset[] = "ANSI_X3.4-1968"; +static const char C_decimal_point[] = "."; +static const char C_thousands_sep[] = ""; + /* Is the C string input 'name' "C" or "POSIX"? If so, and 'name' is the * return of setlocale(), then this is extremely likely to be the C or POSIX * locale. However, the output of setlocale() is documented to be opaque, but @@ -1501,7 +1506,7 @@ S_set_numeric_radix(pTHX_ const bool use_locale) const char * radix = (use_locale) ? my_nl_langinfo(RADIXCHAR, FALSE) /* FALSE => already in dest locale */ - : "."; + : C_decimal_point; sv_setpv(PL_numeric_radix_sv, radix); @@ -1599,9 +1604,9 @@ S_new_numeric(pTHX_ const char *newnum) * THOUSEP can currently (but rarely) cause a race, so avoid doing that, * and just always change the locale if not C nor POSIX on those systems */ if (! PL_numeric_standard) { - PL_numeric_standard = cBOOL(strEQ(".", my_nl_langinfo(RADIXCHAR, + PL_numeric_standard = cBOOL(strEQ(C_decimal_point, my_nl_langinfo(RADIXCHAR, FALSE /* Don't toggle locale */ )) - && strEQ("", my_nl_langinfo(THOUSEP, FALSE))); + && strEQ(C_thousands_sep, my_nl_langinfo(THOUSEP, FALSE))); } # endif @@ -3403,7 +3408,7 @@ S_my_nl_langinfo(const int item, bool toggle) const char * name = querylocale_c(LC_CTYPE); if (isNAME_C_OR_POSIX(name)) { - return "ANSI_X3.4-1968"; + return C_codeset; } /* Find the dot in the locale name */ @@ -3746,7 +3751,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn) # endif # ifdef USE_LOCALE_NUMERIC - PL_numeric_radix_sv = newSVpvs("."); + PL_numeric_radix_sv = newSVpvn(C_decimal_point, strlen(C_decimal_point)); # endif # ifdef LOCALE_ENVIRON_REQUIRED