Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Port Range reify fast-path.
  • Loading branch information
jnthn committed Jun 23, 2013
1 parent 077875a commit c050747
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/core/Range.pm
Expand Up @@ -84,13 +84,13 @@ my class Range is Iterable is Cool does Positional {
?? $!max.Numeric
!! $!max;
my Mu $rpa := nqp::list();
#?if parrot
if nqp::istype($value, Int) && nqp::istype($!max, Int) && !nqp::isbig_I(nqp::decont $!max)
|| nqp::istype($value, Num) {
# Q:PIR optimized for int/num ranges
# optimized for int/num ranges
$value = $value.Num;
my $max = $!max.Num;
my $box_int = nqp::p6bool(nqp::istype($!min, Int));
#?if parrot
Q:PIR {
.local pmc rpa, value_pmc, count_pmc
.local num value, count, max
Expand Down Expand Up @@ -125,14 +125,29 @@ my class Range is Iterable is Cool does Positional {
perl6_container_store value_pmc, $P0
%r = rpa
};
#?endif
#?if !parrot
my num $nvalue = $value;
my num $ncount = $count;
my num $nmax = $max;
my int $icmpstop = $cmpstop;
my int $ibox_int = $box_int;
nqp::while(
(nqp::isgt_n($ncount, 0e0) && nqp::islt_i(nqp::cmp_n($nvalue, $nmax), $icmpstop)),
nqp::stmts(
nqp::push($rpa, $ibox_int
?? nqp::p6box_i($nvalue)
!! nqp::p6box_n($nvalue)),
($nvalue = nqp::add_n($nvalue, 1e0)),
($ncount = nqp::sub_n($ncount, 1e0))
));
$value = nqp::p6box_i($nvalue);
#?endif
}
else {
#?endif
(nqp::push($rpa, $value++); $count--)
while $count > 0 && ($value cmp $realmax) < $cmpstop;
#?if parrot
}
#?endif
if ($value cmp $!max) < $cmpstop {
nqp::push($rpa,
($value.succ cmp $!max < $cmpstop)
Expand Down

0 comments on commit c050747

Please sign in to comment.