Skip to content
Permalink
Browse files

Optimize "for 1,3...9" and "for 9,7...1"

A little more introspection allows those cases to be handle by the
"for ^10" optimization as well.  Makes these sequences a *lot* faster:
for 1,3...999999 about 150x.  Of course, smaller sequences will profit
less.
  • Loading branch information...
lizmat committed Sep 26, 2018
1 parent 49baea7 commit 89787028882bf5faa4aa596a50e320cd6de16f2c
Showing with 15 additions and 6 deletions.
  1. +15 −6 src/Perl6/Optimizer.nqp
@@ -1090,19 +1090,28 @@ class Perl6::Optimizer {
},
'&infix:<...>', -> $op {
my @result;
if get_bound($op[0], 0) -> @lt {
if nqp::istype(@lt[0],QAST::IVal) {
if get_bound($op[1], 0) -> @rt {
if nqp::istype(@rt[0],QAST::IVal) {
if get_bound($op[0], 0) -> @lt { # left side ok
if nqp::istype(@lt[0],QAST::IVal) { # and is an int
if get_bound($op[1], 0) -> @rt { # right side ok
if nqp::istype(@rt[0],QAST::IVal) { # and is an int
@result.push(@lt[0]);
@result.push(@rt[0]);
@result.push(@lt[0].value > @rt[0].value ?? -1 !! 1)
}
}
}
}
else {
# attempt to handle 1,3...11 soon
elsif nqp::istype($op[0],QAST::Op)
&& $op[0].name eq '&infix:<,>' # left side is a list
&& nqp::elems(my $list := $op[0]) == 2 # with 2 elements
&& nqp::istype($list[0][2],QAST::IVal) # first one is an int
&& nqp::istype($list[1][2],QAST::IVal) # second one is an int
&& get_bound($op[1], 0) -> @rt { # right side is ok
if nqp::istype(@rt[0],QAST::IVal) { # and it is an Int
@result.push($list[0][2]);
@result.push(@rt[0]);
@result.push($list[1][2].value - $list[0][2].value);
}
}
@result
}

0 comments on commit 8978702

Please sign in to comment.
You can’t perform that action at this time.