Skip to content

Commit d283e87

Browse files
sybertsee
syber
authored andcommitted
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.
1 parent 4e7ebec commit d283e87

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

gv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,7 @@ Perl_gv_stashpvn(pTHX_ const char *name, U32 namelen, I32 flags)
13601360
(flags & SVf_UTF8) ? HVhek_UTF8 : 0, 0, NULL, 0
13611361
);
13621362
if (he) return INT2PTR(HV*,SvIVX(HeVAL(he)));
1363+
else if (flags & GV_CACHE_ONLY) return NULL;
13631364

13641365
stash = S_stashpvn(aTHX_ name, namelen, flags);
13651366
if (stash && namelen) {

gv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ Return the CV from the GV.
235235
#define GV_ADDMG 0x400 /* add if magical */
236236
#define GV_NO_SVGMAGIC 0x800 /* Skip get-magic on an SV argument;
237237
used only by gv_fetchsv(_nomg) */
238+
#define GV_CACHE_ONLY 0x1000 /* return stash only if found in cache;
239+
used only in flags parameter to gv_stash* family */
238240

239241
/* Flags for gv_fetchmeth_pvn and gv_autoload_pvn*/
240242
#define GV_SUPER 0x1000 /* SUPER::method */

pp_hot.c

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,22 +3000,12 @@ S_method_common(pTHX_ SV* meth, U32* hashp)
30003000
GV* iogv;
30013001
STRLEN packlen;
30023002
const char * const packname = SvPV_nomg_const(sv, packlen);
3003-
const bool packname_is_utf8 = !!SvUTF8(sv);
3004-
const HE* const he =
3005-
(const HE *)hv_common(
3006-
PL_stashcache, NULL, packname, packlen,
3007-
packname_is_utf8 ? HVhek_UTF8 : 0, 0, NULL, 0
3008-
);
3009-
3010-
if (he) {
3011-
stash = INT2PTR(HV*,SvIV(HeVAL(he)));
3012-
DEBUG_o(Perl_deb(aTHX_ "PL_stashcache hit %p for '%"SVf"'\n",
3013-
(void*)stash, SVfARG(sv)));
3014-
goto fetch;
3015-
}
3003+
const U32 packname_utf8 = SvUTF8(sv);
3004+
stash = gv_stashpvn(packname, packlen, packname_utf8 | GV_CACHE_ONLY);
3005+
if (stash) goto fetch;
30163006

30173007
if (!(iogv = gv_fetchpvn_flags(
3018-
packname, packlen, SVf_UTF8 * packname_is_utf8, SVt_PVIO
3008+
packname, packlen, packname_utf8, SVt_PVIO
30193009
)) ||
30203010
!(ob=MUTABLE_SV(GvIO(iogv))))
30213011
{
@@ -3027,16 +3017,8 @@ S_method_common(pTHX_ SV* meth, U32* hashp)
30273017
SVfARG(meth));
30283018
}
30293019
/* assume it's a package name */
3030-
stash = gv_stashpvn(packname, packlen, packname_is_utf8 ? SVf_UTF8 : 0);
3031-
if (!stash)
3032-
packsv = sv;
3033-
else {
3034-
SV* const ref = newSViv(PTR2IV(stash));
3035-
(void)hv_store(PL_stashcache, packname,
3036-
packname_is_utf8 ? -(I32)packlen : (I32)packlen, ref, 0);
3037-
DEBUG_o(Perl_deb(aTHX_ "PL_stashcache caching %p for '%"SVf"'\n",
3038-
(void*)stash, SVfARG(sv)));
3039-
}
3020+
stash = gv_stashpvn(packname, packlen, packname_utf8);
3021+
if (!stash) packsv = sv;
30403022
goto fetch;
30413023
}
30423024
/* it _is_ a filehandle name -- replace with a reference */

0 commit comments

Comments
 (0)