Skip to content

Commit

Permalink
optimize only-0s list_i
Browse files Browse the repository at this point in the history
  • Loading branch information
timo committed Nov 13, 2013
1 parent eada3ad commit c11b5e7
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/vm/parrot/QAST/Operations.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,27 @@ QAST::Operations.add_core_op('list_i', :inlinable(1), -> $qastcomp, $op {
my $list_reg := $*REGALLOC.fresh_p();
my $ops := PIRT::Ops.new(:result($list_reg));
$ops.push_pirop('new', $list_reg, "'ResizableIntegerArray'");

my $all-zeros := 1;
for $op.list {
if !nqp::istype($_, QAST::IVal) || $_.value != 0 {
$all-zeros := 0;
last;
}
}

if +$op.list > 1 {
$ops.push_pirop('assign', $list_reg, +$op.list);
$ops.push_pirop('assign', $list_reg, 0);
$ops.push_pirop('assign', $list_reg, 0) unless $all-zeros;
}

# Push all the things.
for $op.list {
my $post := $qastcomp.coerce($qastcomp.as_post($_), 'i');
$ops.push($post);
$ops.push_pirop('push', $list_reg, $post.result);
unless $all-zeros {
for $op.list {
my $post := $qastcomp.coerce($qastcomp.as_post($_), 'i');
$ops.push($post);
$ops.push_pirop('push', $list_reg, $post.result);
}
}

$ops
Expand Down

0 comments on commit c11b5e7

Please sign in to comment.