Skip to content

Commit

Permalink
Make gv_stashpvn() use PL_stashcache
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
syber authored and tsee committed Aug 20, 2014
1 parent f88f10f commit 4e7ebec
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions gv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1313,8 +1313,8 @@ The most important of which are probably GV_ADD and SVf_UTF8.
=cut
*/

HV*
Perl_gv_stashpvn(pTHX_ const char *name, U32 namelen, I32 flags)
PERL_STATIC_INLINE HV*
S_stashpvn(pTHX_ const char *name, U32 namelen, I32 flags)
{
char smallbuf[128];
char *tmpbuf;
Expand Down Expand Up @@ -1351,6 +1351,25 @@ Perl_gv_stashpvn(pTHX_ const char *name, U32 namelen, I32 flags)
return stash;
}

HV*
Perl_gv_stashpvn(pTHX_ const char *name, U32 namelen, I32 flags)
{
HV* stash;
const HE* const he = (const HE *)hv_common(
PL_stashcache, NULL, name, namelen,
(flags & SVf_UTF8) ? HVhek_UTF8 : 0, 0, NULL, 0
);
if (he) return INT2PTR(HV*,SvIVX(HeVAL(he)));

stash = S_stashpvn(aTHX_ name, namelen, flags);
if (stash && namelen) {
SV* const ref = newSViv(PTR2IV(stash));
hv_store(PL_stashcache, name,
(flags & SVf_UTF8) ? -(I32)namelen : (I32)namelen, ref, 0);
}
return stash;
}

/*
=for apidoc gv_stashsv
Expand Down

0 comments on commit 4e7ebec

Please sign in to comment.