Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Avoid a huge if ladder by replacing it with a hash lookup.
  • Loading branch information
jnthn committed May 8, 2012
1 parent 72358bd commit 81d88d8
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions src/Perl6/Actions.pm
Expand Up @@ -3510,7 +3510,17 @@ class Perl6::Actions is HLL::Actions {
}

## Expressions

my %specials := nqp::hash(
'==>', -> $/, $sym { make_feed($/) },
'==>>', -> $/, $sym { make_feed($/) },
'<==', -> $/, $sym { make_feed($/) },
'<<==', -> $/, $sym { make_feed($/) },
'~~', -> $/, $sym { make_smartmatch($/, 0) },
'!~~', -> $/, $sym { make_smartmatch($/, 1) },
'=', -> $/, $sym { assign_op($/[0].ast, $/[1].ast) },
':=', -> $/, $sym { bind_op($/, $/[0].ast, $/[1].ast, 0) },
'::=', -> $/, $sym { bind_op($/, $/[0].ast, $/[1].ast, 1) }
);
method EXPR($/, $key?) {
unless $key { return 0; }
my $past := $/.ast // $<OPER>.ast;
Expand All @@ -3526,28 +3536,8 @@ class Perl6::Actions is HLL::Actions {
make $past;
return 1;
}
elsif $sym eq '==>' || $sym eq '<==' || $sym eq '==>>' || $sym eq '<<==' {
make make_feed($/);
return 1;
}
elsif $sym eq '~~' {
make make_smartmatch($/, 0);
return 1;
}
elsif $sym eq '!~~' {
make make_smartmatch($/, 1);
return 1;
}
elsif $sym eq '=' {
make assign_op($/[0].ast, $/[1].ast);
return 1;
}
elsif $sym eq ':=' {
make bind_op($/, $/[0].ast, $/[1].ast, 0);
return 1;
}
elsif $sym eq '::=' {
make bind_op($/, $/[0].ast, $/[1].ast, 1);
elsif nqp::existskey(%specials, $sym) {
make %specials{$sym}($/, $sym);
return 1;
}
elsif !$past && ($sym eq 'does' || $sym eq 'but') {
Expand Down

0 comments on commit 81d88d8

Please sign in to comment.