In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/11327fa125f019cb46cfadd1fcec077cbcb8e41f?hp=0529658c13ee0689299688dfce6f5e7e220734d9>

- Log -----------------------------------------------------------------
commit 11327fa125f019cb46cfadd1fcec077cbcb8e41f
Author: Andy Lester <[email protected]>
Date:   Mon Oct 31 11:35:40 2016 +1100

    (perl #129961) code cleanup for clang -Weverything support
    
    This patch simplifies two bits of code that I came across while
    working on supporting the clang -Weverything flag.
    
    The first, in Perl_validate_proto, removes unnecessary variable
    initialization if proto of NULL is passed.
    
    The second, in S_scan_const, rearranges some code and #ifdefs so that
    the convert_unicode and real_range_max variables are only declared
    if EBCDIC is set.  This lets us no longer have to unnecessarily set
    useless variables to make the compiler happy, and it saves us from some
    unnecessary checks on "if (convert_unicode)".  One of the comments says
    "(Compilers should optimize this out for non-EBCDIC)", but now the
    compiler won't even see these unnecessary variables or tests.
-----------------------------------------------------------------------

Summary of changes:
 toke.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/toke.c b/toke.c
index cab34b9..b2d9209 100644
--- a/toke.c
+++ b/toke.c
@@ -1568,7 +1568,7 @@ bool
 Perl_validate_proto(pTHX_ SV *name, SV *proto, bool warn)
 {
     STRLEN len, origlen;
-    char *p = proto ? SvPV(proto, len) : NULL;
+    char *p;
     bool bad_proto = FALSE;
     bool in_brackets = FALSE;
     bool after_slash = FALSE;
@@ -1583,6 +1583,7 @@ Perl_validate_proto(pTHX_ SV *name, SV *proto, bool warn)
     if (!proto)
        return TRUE;
 
+    p = SvPV(proto, len);
     origlen = len;
     for (; len--; p++) {
        if (!isSPACE(*p)) {
@@ -2954,10 +2955,7 @@ S_scan_const(pTHX_ char *start)
                IV range_max;   /* last character in range */
                 STRLEN save_offset;
                 STRLEN grow;
-#ifndef EBCDIC  /* Not meaningful except in EBCDIC, so initialize to false */
-                const bool convert_unicode = FALSE;
-                const IV real_range_max = 0;
-#else
+#ifdef EBCDIC
                 bool convert_unicode;
                 IV real_range_max = 0;
 #endif
@@ -3002,12 +3000,14 @@ S_scan_const(pTHX_ char *start)
 #endif
 
                 if (range_min > range_max) {
+#ifdef EBCDIC
                     if (convert_unicode) {
                         /* Need to convert back to native for meaningful
                          * messages for this platform */
                         range_min = UNI_TO_NATIVE(range_min);
                         range_max = UNI_TO_NATIVE(range_max);
                     }
+#endif
 
                     /* Use the characters themselves for the error message if
                      * ASCII printables; otherwise some visible representation
@@ -3017,6 +3017,7 @@ S_scan_const(pTHX_ char *start)
                         "Invalid range \"%c-%c\" in transliteration operator",
                         (char)range_min, (char)range_max);
                     }
+#ifdef EBCDIC
                     else if (convert_unicode) {
                         /* diag_listed_as: Invalid range "%s" in 
transliteration operator */
                         Perl_croak(aTHX_
@@ -3024,6 +3025,7 @@ S_scan_const(pTHX_ char *start)
                                " in transliteration operator",
                               range_min, range_max);
                     }
+#endif
                     else {
                         /* diag_listed_as: Invalid range "%s" in 
transliteration operator */
                         Perl_croak(aTHX_
@@ -3105,9 +3107,8 @@ S_scan_const(pTHX_ char *start)
                  * (min, max, and the hyphen) */
                 d = save_offset + SvGROW(sv, SvLEN(sv) + grow - 3);
 
-                /* Here, we expand out the range.  On ASCII platforms, the
-                 * compiler should optimize out the 'convert_unicode==TRUE'
-                 * portion of this */
+#ifdef EBCDIC
+                /* Here, we expand out the range. */
                 if (convert_unicode) {
                     IV i;
 
@@ -3126,7 +3127,10 @@ S_scan_const(pTHX_ char *start)
                         }
                    }
                }
-                else {
+                else
+#endif
+                /* Always gets run for ASCII, and sometimes for EBCDIC. */
+                {
                     IV i;
 
                     /* Here, no conversions are necessary, which means that the
@@ -3146,8 +3150,8 @@ S_scan_const(pTHX_ char *start)
                    }
                }
 
-                /* (Compilers should optimize this out for non-EBCDIC).  If the
-                 * original range extended above 255, add in that portion */
+#ifdef EBCDIC
+                /* If the original range extended above 255, add in that 
portion. */
                 if (real_range_max) {
                     *d++ = (char) UTF8_TWO_BYTE_HI(0x100);
                     *d++ = (char) UTF8_TWO_BYTE_LO(0x100);
@@ -3156,6 +3160,7 @@ S_scan_const(pTHX_ char *start)
                     if (real_range_max > 0x100)
                         d = (char*)uvchr_to_utf8((U8*)d, real_range_max);
                 }
+#endif
 
               range_done:
                /* mark the range as done, and continue */

--
Perl5 Master Repository

Reply via email to