Skip to content

Commit

Permalink
locale.c: Rmv S_set_numeric_radix()
Browse files Browse the repository at this point in the history
Previous commits have made this function much smaller, and its branches
can be easily absorbed into the callers, with clearer code, and in fact
removal of a redundant calculation of the locale's radix character,
promised in a previous commit's message
  • Loading branch information
khwilliamson committed May 5, 2021
1 parent 7113feb commit a6e1954
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 36 deletions.
1 change: 0 additions & 1 deletion embed.fnc
Expand Up @@ -3287,7 +3287,6 @@ Sr |void |setlocale_failure_panic_i|const unsigned int cat_index \
|NN const char * failed \
|const line_t caller_0_line \
|const line_t caller_1_line
S |void |set_numeric_radix|const bool use_locale
S |void |new_numeric |NN const char* newnum
S |void |new_LC_ALL |NULLOK const char* unused
S |const char *|toggle_locale_i|const unsigned switch_cat_index \
Expand Down
1 change: 0 additions & 1 deletion embed.h
Expand Up @@ -1734,7 +1734,6 @@
#define new_numeric(a) S_new_numeric(aTHX_ a)
#define restore_toggled_locale_i(a,b) S_restore_toggled_locale_i(aTHX_ a,b)
#define save_to_buffer S_save_to_buffer
#define set_numeric_radix(a) S_set_numeric_radix(aTHX_ a)
#define setlocale_failure_panic_i(a,b,c,d,e) S_setlocale_failure_panic_i(aTHX_ a,b,c,d,e)
#define stdize_locale(a,b,c,d) S_stdize_locale(aTHX_ a,b,c,d)
#define toggle_locale_i(a,b) S_toggle_locale_i(aTHX_ a,b)
Expand Down
44 changes: 10 additions & 34 deletions locale.c
Expand Up @@ -1512,33 +1512,6 @@ S_setlocale_failure_panic_i(pTHX_
NOT_REACHED; /* NOTREACHED */
}

STATIC void
S_set_numeric_radix(pTHX_ const bool use_locale)
{
/* If 'use_locale' is FALSE, set to use a dot for the radix character. If
* TRUE, use the radix character derived from the current locale */

# ifndef USE_LOCALE_NUMERIC

PERL_UNUSED_ARG(use_locale);

# else

if (! use_locale) {
sv_setpv(PL_numeric_radix_sv, C_decimal_point);
}
else {
sv_setsv_nomg(PL_numeric_radix_sv, PL_underlying_radix_sv);
}

DEBUG_L(PerlIO_printf(Perl_debug_log, "Locale radix is '%s', ?UTF-8=%d\n",
SvPVX(PL_numeric_radix_sv),
cBOOL(SvUTF8(PL_numeric_radix_sv))));

# endif /* USE_LOCALE_NUMERIC */

}

STATIC void
S_new_numeric(pTHX_ const char *newnum)
{
Expand Down Expand Up @@ -1645,6 +1618,10 @@ S_new_numeric(pTHX_ const char *newnum)
SvUTF8_on(PL_underlying_radix_sv);
}

DEBUG_L(PerlIO_printf(Perl_debug_log,
"Locale radix is '%s', ?UTF-8=%d\n",
SvPVX(PL_underlying_radix_sv),
cBOOL(SvUTF8(PL_underlying_radix_sv))));

/* This locale is indistinguishable from C (for numeric purposes) if both
* the radix character and the thousands separator are the same as C's.
Expand Down Expand Up @@ -1689,10 +1666,7 @@ S_new_numeric(pTHX_ const char *newnum)
* separator. This is for XS modules, so they don't have to worry about
* the radix being a non-dot. (Core operations that need the underlying
* locale change to it temporarily). */
if (PL_numeric_standard) {
set_numeric_radix(0);
}
else {
if (! PL_numeric_standard) {
set_numeric_standard();
}

Expand All @@ -1719,8 +1693,9 @@ Perl_set_numeric_standard(pTHX)

void_setlocale_c(LC_NUMERIC, "C");
PL_numeric_standard = TRUE;
sv_setpv(PL_numeric_radix_sv, C_decimal_point);

PL_numeric_underlying = PL_numeric_underlying_is_standard;
set_numeric_radix(0);

# endif /* USE_LOCALE_NUMERIC */

Expand All @@ -1744,9 +1719,10 @@ Perl_set_numeric_underlying(pTHX)
PL_numeric_name));

void_setlocale_c(LC_NUMERIC, PL_numeric_name);
PL_numeric_standard = PL_numeric_underlying_is_standard;
PL_numeric_underlying = TRUE;
set_numeric_radix(! PL_numeric_standard);
sv_setsv_nomg(PL_numeric_radix_sv, PL_underlying_radix_sv);

PL_numeric_standard = PL_numeric_underlying_is_standard;

# endif /* USE_LOCALE_NUMERIC */

Expand Down

0 comments on commit a6e1954

Please sign in to comment.