This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perl_sv_vcatpvfn_flags: make 'fill' var a boolean
authorDavid Mitchell <davem@iabyn.com>
Thu, 25 May 2017 11:09:52 +0000 (12:09 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 7 Jun 2017 08:11:04 +0000 (09:11 +0100)
Currently the 'fill' local variable is a char, but it only ever holds the
values ' ' or '0'. Make it into a boolean flag instead.

sv.c

diff --git a/sv.c b/sv.c
index cfa79e2..dfdf57b 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -11457,7 +11457,7 @@ static STRLEN
 S_format_hexfp(pTHX_ char * const buf, const STRLEN bufsize, const char c,
                     const NV nv, const vcatpvfn_long_double_t fv,
                     bool has_precis, STRLEN precis, STRLEN width,
-                    bool alt, char plus, bool left, char fill)
+                    bool alt, char plus, bool left, bool fill)
 {
     /* Hexadecimal floating point. */
     char* p = buf;
@@ -11702,7 +11702,7 @@ S_format_hexfp(pTHX_ char * const buf, const STRLEN bufsize, const char c,
             /* Pad the back with spaces. */
             memset(buf + elen, ' ', gap);
         }
-        else if (fill == '0') {
+        else if (fill) {
             /* Insert the zeros after the "0x" and the
              * the potential sign, but before the digits,
              * otherwise we end up with "0000xH.HHH...",
@@ -11715,7 +11715,7 @@ S_format_hexfp(pTHX_ char * const buf, const STRLEN bufsize, const char c,
                 nmove--;
             }
             Move(zerox, zerox + nzero, nmove, char);
-            memset(zerox, fill, nzero);
+            memset(zerox, fill ? '0' : ' ', nzero);
         }
         else {
             /* Move it to the right. */
@@ -11870,7 +11870,7 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
        char intsize     = 0;         /* size qualifier in "%hi..." etc */
        bool alt         = FALSE;     /* has      "%#..."    */
        bool left        = FALSE;     /* has      "%-..."    */
-       char fill        = ' ';       /* has      "%0..."    */
+       bool fill        = FALSE;     /* has      "%0..."    */
        char plus        = 0;         /* has      "%+..."    */
        STRLEN width     = 0;         /* value of "%NNN..."  */
        bool has_precis  = FALSE;     /* has      "%.NNN..." */
@@ -11966,7 +11966,8 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
                continue;
 
            case '0':
-               fill = *q++;
+               fill = TRUE;
+                q++;
                continue;
 
            case '#':
@@ -12009,8 +12010,10 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
 
        if (!asterisk)
        {
-           if( *q == '0' )
-               fill = *q++;
+           if(*q == '0') {
+               fill = TRUE;
+                q++;
+            }
            width = expect_number(&q);
        }
 
@@ -12321,7 +12324,7 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
 
             if (   args
                 && !intsize
-                && fill == ' '
+                && !fill
                 && !plus
                 && !has_precis
                 && !asterisk
@@ -12612,9 +12615,8 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
                             && !(base == 8 && alt)) /* "%#.0o" prints "0" */
                        elen = 0;
 
-               /* a precision nullifies the 0 flag. */
-                   if (fill == '0')
-                       fill = ' ';
+                    /* a precision nullifies the 0 flag. */
+                    fill = FALSE;
                }
            }
            break;
@@ -12732,7 +12734,7 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
                 && !precis
                 && has_precis
                 && !(width || left || plus || alt)
-                && fill != '0'
+                && !fill
                 && intsize != 'q'
                 && ((eptr = F0convert(nv, ebuf + sizeof ebuf, &elen)))
             )
@@ -12868,7 +12870,7 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
                 && float_need < sizeof(ebuf)
                 && sizeof(ebuf) - float_need > precis
                 && !(width || left || plus || alt)
-                && fill != '0'
+                && !fill
                 && intsize != 'q'
             ) {
                 SNPRINTF_G(fv, ebuf, sizeof(ebuf), precis);
@@ -12944,8 +12946,8 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
                    base = width;
                    do { *--ptr = '0' + (base % 10); } while (base /= 10);
                }
-               if (fill == '0')
-                   *--ptr = fill;
+               if (fill)
+                   *--ptr = '0';
                if (left)
                    *--ptr = '-';
                if (plus)
@@ -13175,16 +13177,16 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
             SvGROW(sv, need);
 
             p = SvEND(sv);
-            if (esignlen && fill == '0') {
+            if (esignlen && fill) {
                 int i;
                 for (i = 0; i < (int)esignlen; i++)
                     *p++ = esignbuf[i];
             }
             if (gap && !left) {
-                memset(p, fill, gap);
+                memset(p, (fill ? '0' : ' '), gap);
                 p += gap;
             }
-            if (esignlen && fill != '0') {
+            if (esignlen && !fill) {
                 int i;
                 for (i = 0; i < (int)esignlen; i++)
                     *p++ = esignbuf[i];