This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Refactor B::PV::PV to use newSVpvn_flags() for both arms of the if.
authorNicholas Clark <nick@ccl4.org>
Sun, 7 Nov 2010 15:19:15 +0000 (15:19 +0000)
committerNicholas Clark <nick@ccl4.org>
Mon, 8 Nov 2010 07:55:09 +0000 (07:55 +0000)
newSVpvn_flags(NULL, whatever, SVs_TEMP) is equivalent to sv_newmortal().

ext/B/B.xs

index fa72c9e..74d15fb 100644 (file)
@@ -1620,10 +1620,15 @@ SvRV(sv)
 void
 SvPV(sv)
        B::PV   sv
+    PREINIT:
+       const char *p;
+       STRLEN len = 0;
+       U32 utf8 = 0;
     CODE:
         if( SvPOK(sv) ) {
-           STRLEN len = SvCUR(sv);
-           const char *p = SvPVX_const(sv);
+           len = SvCUR(sv);
+           p = SvPVX_const(sv);
+           utf8 = SvUTF8(sv);
 #if PERL_VERSION < 10
            /* Before 5.10 (well 931b58fb28fa5ca7), PAD_COMPNAME_GEN was stored
               in SvCUR(), which meant we had to attempt this special casing
@@ -1634,13 +1639,13 @@ SvPV(sv)
                len = strlen(p);
            }
 #endif
-           ST(0) = newSVpvn_flags(p, len, SVs_TEMP | SvUTF8(sv));
         }
         else {
             /* XXX for backward compatibility, but should fail */
             /* croak( "argument is not SvPOK" ); */
-            ST(0) = sv_newmortal();
+           p = NULL;
         }
+       ST(0) = newSVpvn_flags(p, len, SVs_TEMP | utf8);
 
 # This used to read 257. I think that that was buggy - should have been 258.
 # (The "\0", the flags byte, and 256 for the table.  Not that anything