This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Rmv mro_method_changed_in call on stub upgraded to const
authorFather Chrysostomos <sprout@cpan.org>
Mon, 11 Jun 2012 05:39:44 +0000 (22:39 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 15 Jun 2012 19:28:15 +0000 (12:28 -0700)
If a subroutine stub exists and a new subroutine is defined with the
same name, that new subroutine’s body is attached to the stub.  So
there are no changes from the point of view of method lookup.

For most subs, mro_method_changed_in is not called in this case.

For constant subs, it was being called.

In the case where a new sub is being created, we know that
cv == GvCV(gv) and GvSTASH(gv) is set, so checking CvSTASH is
unnecessary.

op.c

diff --git a/op.c b/op.c
index 0ff8f67..170a0be 100644 (file)
--- a/op.c
+++ b/op.c
@@ -6864,7 +6864,6 @@ Perl_newATTRSUB_flags(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs,
        }
     }
     if (const_sv) {
-       HV *stash;
        SvREFCNT_inc_simple_void_NN(const_sv);
        if (cv) {
            assert(!CvROOT(cv) && !CvCONST(cv));
@@ -6880,15 +6879,10 @@ Perl_newATTRSUB_flags(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs,
                NULL, name, namlen, name_is_utf8 ? SVf_UTF8 : 0,
                const_sv
            );
-       }
-       stash =
-            (CvGV(cv) && GvSTASH(CvGV(cv)))
-                ? GvSTASH(CvGV(cv))
-                : CvSTASH(cv)
-                    ? CvSTASH(cv)
-                    : PL_curstash;
-       if (HvENAME_HEK(stash))
-            mro_method_changed_in(stash); /* sub Foo::Bar () { 123 } */
+           if (HvENAME_HEK(GvSTASH(gv)))
+               /* sub Foo::bar { (shift)+1 } */
+               mro_method_changed_in(GvSTASH(gv));
+       }                               /* sub Foo::Bar () { 123 } */
        if (PL_madskills)
            goto install_block;
        op_free(block);