Skip to content

Commit 4e7ebec

Browse files
sybertsee
syber
authored andcommitted
Make gv_stashpvn() use PL_stashcache
perl has a stash name lookup cache, which is currently just used for looking up up class names in Some::Class->method calls. This means that a lookup of the class name 'A::B::C' gets reduced from doing several stash lookups (e.g. $::{'A::'}{'B::'}{'C::'}) to a single cache lookup (e.g. $PL_stashcache{'A::B::C::'}, so to speak). Make gv_stashpvn() use this cache too, which means that all package name lookups benefit, not just class method calls. Among other things, this also indirectly affects bless operations both from Perl (OP_BLESS) and XS.
1 parent f88f10f commit 4e7ebec

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

gv.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,8 +1313,8 @@ The most important of which are probably GV_ADD and SVf_UTF8.
13131313
=cut
13141314
*/
13151315

1316-
HV*
1317-
Perl_gv_stashpvn(pTHX_ const char *name, U32 namelen, I32 flags)
1316+
PERL_STATIC_INLINE HV*
1317+
S_stashpvn(pTHX_ const char *name, U32 namelen, I32 flags)
13181318
{
13191319
char smallbuf[128];
13201320
char *tmpbuf;
@@ -1351,6 +1351,25 @@ Perl_gv_stashpvn(pTHX_ const char *name, U32 namelen, I32 flags)
13511351
return stash;
13521352
}
13531353

1354+
HV*
1355+
Perl_gv_stashpvn(pTHX_ const char *name, U32 namelen, I32 flags)
1356+
{
1357+
HV* stash;
1358+
const HE* const he = (const HE *)hv_common(
1359+
PL_stashcache, NULL, name, namelen,
1360+
(flags & SVf_UTF8) ? HVhek_UTF8 : 0, 0, NULL, 0
1361+
);
1362+
if (he) return INT2PTR(HV*,SvIVX(HeVAL(he)));
1363+
1364+
stash = S_stashpvn(aTHX_ name, namelen, flags);
1365+
if (stash && namelen) {
1366+
SV* const ref = newSViv(PTR2IV(stash));
1367+
hv_store(PL_stashcache, name,
1368+
(flags & SVf_UTF8) ? -(I32)namelen : (I32)namelen, ref, 0);
1369+
}
1370+
return stash;
1371+
}
1372+
13541373
/*
13551374
=for apidoc gv_stashsv
13561375

0 commit comments

Comments
 (0)