This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Eliminate most *printf-like calls that use a simple "%c" format,
authorNicholas Clark <nick@ccl4.org>
Fri, 5 Oct 2007 19:48:27 +0000 (19:48 +0000)
committerNicholas Clark <nick@ccl4.org>
Fri, 5 Oct 2007 19:48:27 +0000 (19:48 +0000)
replacing them with constructions that are more efficient because they
avoid the overhead of the *printf format parser and interpreter code.

p4raw-id: //depot/perl@32034

dump.c
regcomp.c
toke.c
utf8.c

diff --git a/dump.c b/dump.c
index dce8630..bdaf41a 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -279,7 +279,8 @@ Perl_pv_escape( pTHX_ SV *dsv, char const * const str,
             sv_catpvn(dsv, octbuf, chsize);
             wrote += chsize;
        } else {
-            Perl_sv_catpvf( aTHX_ dsv, "%c", c);
+           const char string = (char) c;
+            sv_catpvn(dsv, &string, 1);
            wrote++;
        }
         if ( flags & PERL_PV_ESCAPE_FIRSTCHAR ) 
@@ -2243,7 +2244,8 @@ Perl_sv_catxmlpvn(pTHX_ SV *dsv, const char *pv, STRLEN len, int utf8)
                    Perl_sv_catpvf(aTHX_ dsv, "&#x%X;", c);
                }
                else {
-                   Perl_sv_catpvf(aTHX_ dsv, "%c", c);
+                   const char string = (char) c;
+                   sv_catpvn(dsv, &string, 1);
                }
                break;
            }
index dd48f3c..8757eb1 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -6484,6 +6484,7 @@ S_reg_namedseq(pTHX_ RExC_state_t *pRExC_state, UV *valuep)
             | PERL_SCAN_DISALLOW_PREFIX
             | (SIZE_ONLY ? PERL_SCAN_SILENT_ILLDIGIT : 0);
         UV cp;
+       unsigned char string;
         len = (STRLEN)(endbrace - name - 2);
         cp = grok_hex(name + 2, &len, &fl, NULL);
         if ( len != (STRLEN)(endbrace - name - 2) ) {
@@ -6495,7 +6496,8 @@ S_reg_namedseq(pTHX_ RExC_state_t *pRExC_state, UV *valuep)
             *valuep = cp;
             return NULL;
         }
-        sv_str= Perl_newSVpvf_nocontext("%c",(int)cp);
+       string = (unsigned char) cp;
+        sv_str= newSVpvn(&string, 1);
     } else {
         /* fetch the charnames handler for this scope */
         HV * const table = GvHV(PL_hintgv);
@@ -9666,10 +9668,12 @@ S_put_byte(pTHX_ SV *sv, int c)
 {
     if (isCNTRL(c) || c == 255 || !isPRINT(c))
        Perl_sv_catpvf(aTHX_ sv, "\\%o", c);
-    else if (c == '-' || c == ']' || c == '\\' || c == '^')
-       Perl_sv_catpvf(aTHX_ sv, "\\%c", c);
-    else
-       Perl_sv_catpvf(aTHX_ sv, "%c", c);
+    else {
+       const unsigned char string = (unsigned char) c;
+       if (c == '-' || c == ']' || c == '\\' || c == '^')
+           sv_catpvs(sv, "\\");
+       sv_catpvn(sv, &string, 1);
+    }
 }
 
 
diff --git a/toke.c b/toke.c
index be7bacf..7037a43 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -12510,8 +12510,10 @@ Perl_yyerror(pTHX_ const char *s)
        SV * const where_sv = sv_2mortal(newSVpvs("next char "));
        if (yychar < 32)
            Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
-       else if (isPRINT_LC(yychar))
-           Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
+       else if (isPRINT_LC(yychar)) {
+           const unsigned char string = (unsigned char) yychar;
+           sv_catpvn(where_sv, &string, 1);
+       }
        else
            Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
        where = SvPVX_const(where_sv);
diff --git a/utf8.c b/utf8.c
index a761d82..c665a41 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -2167,12 +2167,14 @@ Perl_pv_uni_display(pTHX_ SV *dsv, const U8 *spv, STRLEN len, STRLEN pvlim, UV f
                 default: break;
                 }
                 if (ok) {
-                    Perl_sv_catpvf(aTHX_ dsv, "\\%c", ok);
+                    const unsigned char string = (unsigned char) ok;
+                    sv_catpvn(dsv, &string, 1);
                 }
             }
             /* isPRINT() is the locale-blind version. */
             if (!ok && (flags & UNI_DISPLAY_ISPRINT) && isPRINT(c)) {
-                Perl_sv_catpvf(aTHX_ dsv, "%c", c);
+                const unsigned char string = (unsigned char) c;
+                sv_catpvn(dsv, &string, 1);
                 ok = 1;
             }
         }