summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsyber <syber@crazypanda.ru>2014-08-08 21:06:10 +0400
committerSteffen Mueller <smueller@cpan.org>2014-08-20 09:12:01 +0200
commitd283e8761b900561d01c1d8807b4a2f19e0c28c1 (patch)
treee91a18cd7610b34726f5054d1988c6c0db79568c
parent4e7ebec5b38b722121a7df00ce087bb49f1c6d43 (diff)
downloadperl-d283e8761b900561d01c1d8807b4a2f19e0c28c1.tar.gz
Make S_method_common use gv_stashpvn instead of copypasted cache usage
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.
-rw-r--r--gv.c1
-rw-r--r--gv.h2
-rw-r--r--pp_hot.c30
3 files changed, 9 insertions, 24 deletions
diff --git a/gv.c b/gv.c
index 47793eff2a..500e24b2c2 100644
--- 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 d7ca92fb58..5071591742 100644
--- 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 */
diff --git a/pp_hot.c b/pp_hot.c
index 12a22cb348..333bcc8b48 100644
--- 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 */