Re: [PATCH] various RC1 nits
[p5sagit/p5-mst-13.2.git] / pp_ctl.c
index d925171..39f18b2 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3018,13 +3018,13 @@ S_check_type_and_open(pTHX_ const char *name)
     return PerlIO_open(name, PERL_SCRIPT_MODE);
 }
 
+#ifndef PERL_DISABLE_PMC
 STATIC PerlIO *
 S_doopen_pm(pTHX_ const char *name, const STRLEN namelen)
 {
-#ifndef PERL_DISABLE_PMC
     PerlIO *fp;
 
-    if (namelen > 3 && strEQ(name + namelen - 3, ".pm")) {
+    if (namelen > 3 && memEQs(name + namelen - 3, 3, ".pm")) {
        SV *const pmcsv = newSV(namelen + 2);
        char *const pmc = SvPVX(pmcsv);
        Stat_t pmcstat;
@@ -3045,10 +3045,10 @@ S_doopen_pm(pTHX_ const char *name, const STRLEN namelen)
        fp = check_type_and_open(name);
     }
     return fp;
+}
 #else
-    return check_type_and_open(name);
+#  define doopen_pm(name, namelen) check_type_and_open(name)
 #endif /* !PERL_DISABLE_PMC */
-}
 
 PP(pp_require)
 {
@@ -3222,6 +3222,7 @@ PP(pp_require)
 #endif
        {
            namesv = newSV(0);
+           sv_upgrade(namesv, SVt_PV);
            for (i = 0; i <= AvFILL(ar); i++) {
                SV * const dirsv = *av_fetch(ar, i, TRUE);
 
@@ -3351,7 +3352,16 @@ PP(pp_require)
                        || (*name == ':' && name[1] != ':' && strchr(name+2, ':'))
 #endif
                  ) {
-                   const char *dir = SvOK(dirsv) ? SvPV_nolen_const(dirsv) : "";
+                   const char *dir;
+                   STRLEN dirlen;
+
+                   if (SvOK(dirsv)) {
+                       dir = SvPV_const(dirsv, dirlen);
+                   } else {
+                       dir = "";
+                       dirlen = 0;
+                   }
+
 #ifdef MACOS_TRADITIONAL
                    char buf1[256];
                    char buf2[256];
@@ -3379,7 +3389,26 @@ PP(pp_require)
                                       "%s\\%s",
                                       dir, name);
 #    else
-                   Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name);
+                   /* The equivalent of                    
+                      Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name);
+                      but without the need to parse the format string, or
+                      call strlen on either pointer, and with the correct
+                      allocation up front.  */
+                   {
+                       char *tmp = SvGROW(namesv, dirlen + len + 2);
+
+                       memcpy(tmp, dir, dirlen);
+                       tmp +=dirlen;
+                       *tmp++ = '/';
+                       /* name came from an SV, so it will have a '\0' at the
+                          end that we can copy as part of this memcpy().  */
+                       memcpy(tmp, name, len + 1);
+
+                       SvCUR_set(namesv, dirlen + len + 1);
+
+                       /* Don't even actually have to turn SvPOK_on() as we
+                          access it directly with SvPVX() below.  */
+                   }
 #    endif
 #  endif
 #endif