Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
cache symbols found in SETTING.
  • Loading branch information
timo committed Apr 14, 2013
1 parent ee68af8 commit 05ec31b
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions src/Perl6/Optimizer.pm
Expand Up @@ -35,6 +35,7 @@ class Perl6::Optimizer {

# The Setting, which contains things like Signature and Parameter.
has $!SETTING;
has %!SETTING_CACHE;

has %!foldable_junction;
has %!foldable_outer;
Expand Down Expand Up @@ -174,21 +175,32 @@ class Perl6::Optimizer {
return 0;
}

method find_setting() {
if nqp::defined($!SETTING) {
return $!SETTING;
method find_in_setting($symbol) {
if !nqp::defined($!SETTING) {
my int $i := +@!block_stack;
while $i > 0 && !nqp::defined($!SETTING) {
$i := $i - 1;
my $block := @!block_stack[$i];
my %sym := $block.symbol("!CORE_MARKER");
if +%sym {
$!SETTING := $block;
}
}
nqp::die("Optimizer couldn't find CORE while looking for $symbol.");
} else {
if nqp::existskey(%!SETTING_CACHE, $symbol) {
return %!SETTING_CACHE{$symbol};
}
}
my int $i := +@!block_stack;
while $i > 0 {
$i := $i - 1;
my $block := @!block_stack[$i];
my %sym := $block.symbol("!CORE_MARKER");
if +%sym {
$!SETTING := $block;
return $block;
my %sym := $!SETTING.symbol($symbol);
if +%sym {
if nqp::existskey(%sym, 'value') {
%!SETTING_CACHE{$symbol} := %sym<value>;
return %sym<value>;
} else {
nqp::die("Optimizer: cannot find $symbol in SETTING.");
}
}
nqp::die("Optimizer couldn't find CORE.");
}

method can_chain_junction_be_warped($node) {
Expand Down Expand Up @@ -254,7 +266,7 @@ class Perl6::Optimizer {
$found := 1;
}
if $found == 1 {
my $signature := self.find_setting().symbol("Signature")<value>;
my $signature := self.find_in_setting("Signature");
my $iter := nqp::iterator(nqp::getattr($obj.signature, $signature, '$!params'));
while $iter {
my $p := nqp::shift($iter);
Expand Down

0 comments on commit 05ec31b

Please sign in to comment.