Make S_method_common use gv_stashpvn instead of copypasted cache usage
authorsyber <syber@crazypanda.ru>
Fri, 8 Aug 2014 17:06:10 +0000 (21:06 +0400)
committerSteffen Mueller <smueller@cpan.org>
Wed, 20 Aug 2014 07:12:01 +0000 (09:12 +0200)
The previous commit copied the PL_stashcache handling code from
S_method_common() to gv_stashpvn(), so now we can call that function
directly rather than doing it ourselves.

gv.c
gv.h
pp_hot.c

diff --git a/gv.c b/gv.c
index 47793ef..500e24b 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -1360,6 +1360,7 @@ Perl_gv_stashpvn(pTHX_ const char *name, U32 namelen, I32 flags)
         (flags & SVf_UTF8) ? HVhek_UTF8 : 0, 0, NULL, 0
     );
     if (he) return INT2PTR(HV*,SvIVX(HeVAL(he)));
+    else if (flags & GV_CACHE_ONLY) return NULL;
 
     stash = S_stashpvn(aTHX_ name, namelen, flags);
     if (stash && namelen) {
diff --git a/gv.h b/gv.h
index d7ca92f..5071591 100644 (file)
--- a/gv.h
+++ b/gv.h
@@ -235,6 +235,8 @@ Return the CV from the GV.
 #define GV_ADDMG       0x400   /* add if magical */
 #define GV_NO_SVGMAGIC 0x800   /* Skip get-magic on an SV argument;
                                   used only by gv_fetchsv(_nomg) */
+#define GV_CACHE_ONLY  0x1000  /* return stash only if found in cache;
+                                  used only in flags parameter to gv_stash* family */
 
 /* Flags for gv_fetchmeth_pvn and gv_autoload_pvn*/
 #define GV_SUPER       0x1000  /* SUPER::method */
index 12a22cb..333bcc8 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -3000,22 +3000,12 @@ S_method_common(pTHX_ SV* meth, U32* hashp)
        GV* iogv;
         STRLEN packlen;
         const char * const packname = SvPV_nomg_const(sv, packlen);
-        const bool packname_is_utf8 = !!SvUTF8(sv);
-        const HE* const he =
-           (const HE *)hv_common(
-                PL_stashcache, NULL, packname, packlen,
-                packname_is_utf8 ? HVhek_UTF8 : 0, 0, NULL, 0
-           );
-         
-        if (he) { 
-            stash = INT2PTR(HV*,SvIV(HeVAL(he)));
-            DEBUG_o(Perl_deb(aTHX_ "PL_stashcache hit %p for '%"SVf"'\n",
-                             (void*)stash, SVfARG(sv)));
-            goto fetch;
-        }
+        const U32 packname_utf8 = SvUTF8(sv);
+        stash = gv_stashpvn(packname, packlen, packname_utf8 | GV_CACHE_ONLY);
+        if (stash) goto fetch;
 
        if (!(iogv = gv_fetchpvn_flags(
-               packname, packlen, SVf_UTF8 * packname_is_utf8, SVt_PVIO
+               packname, packlen, packname_utf8, SVt_PVIO
             )) ||
            !(ob=MUTABLE_SV(GvIO(iogv))))
        {
@@ -3027,16 +3017,8 @@ S_method_common(pTHX_ SV* meth, U32* hashp)
                                  SVfARG(meth));
            }
            /* assume it's a package name */
-           stash = gv_stashpvn(packname, packlen, packname_is_utf8 ? SVf_UTF8 : 0);
-           if (!stash)
-               packsv = sv;
-            else {
-               SV* const ref = newSViv(PTR2IV(stash));
-               (void)hv_store(PL_stashcache, packname,
-                                packname_is_utf8 ? -(I32)packlen : (I32)packlen, ref, 0);
-                DEBUG_o(Perl_deb(aTHX_ "PL_stashcache caching %p for '%"SVf"'\n",
-                                 (void*)stash, SVfARG(sv)));
-           }
+           stash = gv_stashpvn(packname, packlen, packname_utf8);
+           if (!stash) packsv = sv;
            goto fetch;
        }
        /* it _is_ a filehandle name -- replace with a reference */