Simplify gv:S_maybe_add_coresub
authorFather Chrysostomos <sprout@cpan.org>
Sun, 1 Jan 2012 21:06:27 +0000 (13:06 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 1 Jan 2012 21:07:30 +0000 (13:07 -0800)
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.

gv.c
op.c

diff --git a/gv.c b/gv.c
index c0baa09..3005895 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -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) {
diff --git a/op.c b/op.c
index 3e6b0b9..f0ac7b9 100644 (file)
--- a/op.c
+++ b/op.c
@@ -6469,7 +6469,9 @@ Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
        ps = NULL;
 
     if (name) {
-       gv = gv_fetchsv(cSVOPo->op_sv, gv_fetch_flags, SVt_PVCV);
+       gv = isGV(cSVOPo->op_sv)
+             ? (GV *)cSVOPo->op_sv
+             : gv_fetchsv(cSVOPo->op_sv, gv_fetch_flags, SVt_PVCV);
        has_name = TRUE;
     } else if (PERLDB_NAMEANON && CopLINE(PL_curcop)) {
        SV * const sv = sv_newmortal();