Keep PL_numeric_radix_sv always set
authorKarl Williamson <khw@cpan.org>
Thu, 18 Jan 2018 22:45:19 +0000 (15:45 -0700)
committerKarl Williamson <khw@cpan.org>
Wed, 31 Jan 2018 05:58:15 +0000 (22:58 -0700)
Previously this was removed if the radix was dot.  By keeping it set to
a dot, we simplify some code, removing some branches.

locale.c
numeric.c
sv.c

index e29d0c4..bf1a0e0 100644 (file)
--- a/locale.c
+++ b/locale.c
@@ -388,19 +388,12 @@ S_set_numeric_radix(pTHX_ const bool use_locale)
 #if defined(USE_LOCALE_NUMERIC) && (   defined(HAS_LOCALECONV)              \
                                     || defined(HAS_NL_LANGINFO))
 
-    /* We only set up the radix SV if we are to use a locale radix ... */
-    if (use_locale) {
-        const char * radix = my_nl_langinfo(PERL_RADIXCHAR, FALSE);
+        const char * radix = (use_locale)
+                             ? my_nl_langinfo(PERL_RADIXCHAR, FALSE)
                                           /* FALSE => already in dest locale */
-        /* ... and the character being used isn't a dot */
-        if (strNE(radix, ".")) {
+                             : ".";
 
-            if (PL_numeric_radix_sv) {
                 sv_setpv(PL_numeric_radix_sv, radix);
-            }
-            else {
-                PL_numeric_radix_sv = newSVpv(radix, 0);
-            }
 
             /* If this is valid UTF-8 that isn't totally ASCII, and we are in
              * a UTF-8 locale, then mark the radix as being in UTF-8 */
@@ -410,25 +403,13 @@ S_set_numeric_radix(pTHX_ const bool use_locale)
             {
                 SvUTF8_on(PL_numeric_radix_sv);
             }
-            goto done;
-        }
-    }
-
-    SvREFCNT_dec(PL_numeric_radix_sv);
-    PL_numeric_radix_sv = NULL;
-
-  done: ;
 
 #  ifdef DEBUGGING
 
     if (DEBUG_L_TEST || debug_initialization) {
         PerlIO_printf(Perl_debug_log, "Locale radix is '%s', ?UTF-8=%d\n",
-                                          (PL_numeric_radix_sv)
-                                           ? SvPVX(PL_numeric_radix_sv)
-                                           : "NULL",
-                                          (PL_numeric_radix_sv)
-                                           ? cBOOL(SvUTF8(PL_numeric_radix_sv))
-                                           : 0);
+                                           SvPVX(PL_numeric_radix_sv),
+                                           cBOOL(SvUTF8(PL_numeric_radix_sv)));
     }
 
 #  endif
@@ -2046,6 +2027,8 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
     my_strlcpy(PL_locale_utf8ness, C_and_POSIX_utf8ness,
                sizeof(PL_locale_utf8ness));
 
+    PL_numeric_radix_sv = newSVpvs(".");
+
 #  ifdef LOCALE_ENVIRON_REQUIRED
 
     /*
index ea500e9..494e72e 100644 (file)
--- a/numeric.c
+++ b/numeric.c
@@ -524,7 +524,7 @@ Perl_grok_numeric_radix(pTHX_ const char **sp, const char *send)
     if (IN_LC(LC_NUMERIC)) {
         DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
         STORE_LC_NUMERIC_FORCE_TO_UNDERLYING();
-        if (PL_numeric_radix_sv) {
+        {
             STRLEN len;
             const char * const radix = SvPV(PL_numeric_radix_sv, len);
             if (*sp + len <= send && memEQ(*sp, radix, len)) {
diff --git a/sv.c b/sv.c
index bd655d0..b0ae323 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -11713,7 +11713,7 @@ S_format_hexfp(pTHX_ char * const buf, const STRLEN bufsize, const char c,
 #ifndef USE_LOCALE_NUMERIC
             *p++ = '.';
 #else
-            if (PL_numeric_radix_sv && IN_LC(LC_NUMERIC)) {
+            if (IN_LC(LC_NUMERIC)) {
                 STRLEN n;
                 const char* r = SvPV(PL_numeric_radix_sv, n);
                 Copy(r, p, n, char);
@@ -12905,7 +12905,7 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
                 lc_numeric_set = TRUE;
             }
 
-            if (PL_numeric_radix_sv && IN_LC(LC_NUMERIC)) {
+            if (IN_LC(LC_NUMERIC)) {
                 /* this can't wrap unless PL_numeric_radix_sv is a string
                  * consuming virtually all the 32-bit or 64-bit address
                  * space