diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-01-01 13:06:27 -0800 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-01-01 13:07:30 -0800 |
commit | 8756617677dbda9a9ac19ac3155ca3bbabbf75a8 (patch) | |
tree | 278710b46c7769f71bb732a6ad4db5f158658453 /gv.c | |
parent | 62f789982833b2c6a9005f78da558557992fcf8f (diff) | |
download | perl-8756617677dbda9a9ac19ac3155ca3bbabbf75a8.tar.gz |
Simplify gv:S_maybe_add_coresub
It was working around the fact that newATTRSUB expects to be able to
look up the GV by name.
And for speed, it was going through hoops to try to avoid creating
extra SVs holding the name unnecessarily.
By tweaking newATTRSUB to accept a GV instead of a name, we can sim-
plify not only S_maybe_add_coresub but all its callers, too.
Diffstat (limited to 'gv.c')
-rw-r--r-- | gv.c | 29 |
1 files changed, 7 insertions, 22 deletions
@@ -437,8 +437,7 @@ static void core_xsub(pTHX_ CV* cv); static GV * S_maybe_add_coresub(pTHX_ HV * const stash, GV *gv, - const char * const name, const STRLEN len, - const char * const fullname, STRLEN const fullen) + const char * const name, const STRLEN len) { const int code = keyword(name, len, 1); static const char file[] = __FILE__; @@ -452,11 +451,7 @@ S_maybe_add_coresub(pTHX_ HV * const stash, GV *gv, assert(gv || stash); assert(name); - assert(stash || fullname); - if (!fullname && !HvENAME(stash)) return NULL; /* pathological case - that would require - inlining newATTRSUB */ if (code >= 0) return NULL; /* not overridable */ switch (-code) { /* no support for \&CORE::infix; @@ -517,19 +512,12 @@ S_maybe_add_coresub(pTHX_ HV * const stash, GV *gv, it this order as we need an op number before calling new ATTRSUB. */ (void)core_prototype((SV *)cv, name, code, &opnum); - if (stash && (fullname || !fullen)) + if (stash) (void)hv_store(stash,name,len,(SV *)gv,0); if (ampable) { - SV *tmpstr; CvLVALUE_on(cv); - if (!fullname) { - tmpstr = newSVhek(HvENAME_HEK(stash)); - sv_catpvs(tmpstr, "::"); - sv_catpvn(tmpstr,name,len); - } - else tmpstr = newSVpvn_share(fullname,fullen,0); newATTRSUB(oldsavestack_ix, - newSVOP(OP_CONST, 0, tmpstr), + newSVOP(OP_CONST, 0, (SV *)gv), NULL,NULL, coresub_op( opnum @@ -688,7 +676,7 @@ Perl_gv_fetchmeth_pvn(pTHX_ HV *stash, const char *name, STRLEN len, I32 level, } else if (len > 1 /* shortest is uc */ && HvNAMELEN_get(stash) == 4 && strnEQ(hvname, "CORE", 4) - && S_maybe_add_coresub(aTHX_ stash,topgv,name,len,0,1)) + && S_maybe_add_coresub(aTHX_ NULL,topgv,name,len)) goto have_gv; } @@ -727,7 +715,7 @@ Perl_gv_fetchmeth_pvn(pTHX_ HV *stash, const char *name, STRLEN len, I32 level, const char *hvname = HvNAME(cstash); assert(hvname); if (strnEQ(hvname, "CORE", 4) && (candidate = - S_maybe_add_coresub(aTHX_ cstash,NULL,name,len,0,0) + S_maybe_add_coresub(aTHX_ cstash,NULL,name,len) )) goto have_candidate; } @@ -1730,11 +1718,8 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags, if (len > 1 /* shortest is uc */ && HvNAMELEN_get(stash) == 4) { /* Avoid null warning: */ const char * const stashname = HvNAME(stash); assert(stashname); - if (strnEQ(stashname, "CORE", 4) - && S_maybe_add_coresub(aTHX_ - addmg ? stash : 0, gv, name, len, nambeg, full_len - )) - addmg = 0; + if (strnEQ(stashname, "CORE", 4)) + S_maybe_add_coresub(aTHX_ 0, gv, name, len); } } else if (len > 1) { |