Skip to content

Commit

Permalink
Reuse the containers that magic variables containers are cloned off.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Jan 16, 2017
1 parent b64da29 commit 2204a1a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Perl6/World.nqp
Expand Up @@ -1433,7 +1433,7 @@ class Perl6::World is HLL::World {

# Installs a lexical symbol. Takes a QAST::Block object, name and
# the type of container to install.
method install_lexical_container($block, str $name, %cont_info, $descriptor, :$scope, :$package) {
method install_lexical_container($block, str $name, %cont_info, $descriptor, :$scope, :$package, :$cont = self.build_container(%cont_info, $descriptor)) {
# Add to block, if needed. Note that it doesn't really have
# a compile time value.
my $var;
Expand Down Expand Up @@ -1478,9 +1478,6 @@ class Perl6::World is HLL::World {
return nqp::null();
}

# Build container.
my $cont := self.build_container(%cont_info, $descriptor);
self.add_object($cont);
$block.symbol($name, :value($cont));
self.install_package_symbol_unchecked($package, $name, $cont) if $scope eq 'our';

Expand All @@ -1500,7 +1497,7 @@ class Perl6::World is HLL::World {
$cd
}

# Builds a container.
# Builds a container and adds it to the SC.
method build_container(%cont_info, $descriptor) {
my $cont;
my $cont_type := %cont_info<container_type>;
Expand All @@ -1524,6 +1521,7 @@ class Perl6::World is HLL::World {
$cont := $cont_type.new;
try nqp::bindattr($cont, %cont_info<container_base>, '$!descriptor', $descriptor);
}
self.add_object($cont);
$cont
}

Expand Down Expand Up @@ -1678,13 +1676,13 @@ class Perl6::World is HLL::World {
}

# Installs one of the magical lexicals ($_, $/ and $!). Uses a cache to
# avoid massive duplication of container descriptors.
# avoid massive duplication of containers and container descriptors.
method install_lexical_magical($block, $name) {
my %magical_cds := self.context().magical_cds();

if nqp::existskey(%magical_cds, $name) {
my $mcd := nqp::atkey(%magical_cds, $name);
self.install_lexical_container($block, $name, $mcd[0], $mcd[1]);
self.install_lexical_container($block, $name, $mcd[0], $mcd[1], :cont($mcd[2]));
}
else {
my $Mu := self.find_symbol(['Mu']);
Expand All @@ -1702,8 +1700,10 @@ class Perl6::World is HLL::World {
my $desc :=
self.create_container_descriptor($Mu, 1, $name, $WHAT, 1);

%magical_cds{$name} := [%info, $desc];
self.install_lexical_container($block, $name, %info, $desc);
my $cont := self.build_container(%info, $desc);

%magical_cds{$name} := [%info, $desc, $cont];
self.install_lexical_container($block, $name, %info, $desc, :cont($cont));
}
}

Expand Down

0 comments on commit 2204a1a

Please sign in to comment.