This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Avoid creating GVs when subs are declared
authorFather Chrysostomos <sprout@cpan.org>
Mon, 1 Sep 2014 03:13:21 +0000 (20:13 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 15 Sep 2014 13:19:32 +0000 (06:19 -0700)
commit2eaf799e74b14dc77b90d5484a3fd4ceac12b46a
treed472277495cf7140a2aec82d0593edfa9ed3b0fb
parentc831c5ee90b91c179042ccda588910ba60808970
Avoid creating GVs when subs are declared

This patch changes ‘sub foo {...}’ declarations to store subroutine
references in the stash, to save memory.

Typeglobs still notionally exist.  Accessing CvGV(cv) will reify them.
Hence, currently the savings are lost when a sub call is compiled.

$ ./miniperl -e 'sub foo{} BEGIN { warn $::{foo} } foo(); BEGIN { warn $::{foo} }'
CODE(0x7f8ef082ad98) at -e line 1.
*main::foo at -e line 1.

This optimisation is skipped if the subroutine declaration contains a
package separator.

Concerning the changes in caller.t, this code:

    sub foo { print +(caller(0))[3],"\n" }
    my $fooref = delete $::{foo};
    $fooref -> ();

used to crash in 5.7.3 or thereabouts.  It was fixed by 16658 (aka
07b8c804e8) to produce ‘(unknown)’ instead.  Then in 5.13.3 it was
changed (by 803f274) to produce ‘main::__ANON__’ instead.  So the
tests are really checking that we don’t get a crash.  I think it is
acceptable that it has now changed to ‘main::foo’.
embed.fnc
gv.c
op.c
pp.c
proto.h
t/op/caller.t
t/op/gv.t
t/uni/gv.t
t/uni/parser.t
toke.c
universal.c