Skip to content

Commit

Permalink
Streamlining Rakudo::SEQUENCE.iterator (4/N)
Browse files Browse the repository at this point in the history
- use ternaries in lambda's where possible
  • Loading branch information
lizmat committed Mar 21, 2020
1 parent 58fa99b commit cf6177e
Showing 1 changed file with 43 additions and 32 deletions.
75 changes: 43 additions & 32 deletions src/core.c/Rakudo/SEQUENCE.pm6
Expand Up @@ -26,21 +26,22 @@ class Rakudo::SEQUENCE {
$cmp < 0 && nqp::istype($a,Stringy)
?? {
my $new := .succ;
last if $new after $endpoint
or $new.chars > $endpoint.chars;
$new;
$new after $endpoint || $new.chars > $endpoint.chars
?? (last)
!! $new
}
!! $cmp < 0
?? {
my $new := .succ;
last if $new after $endpoint;
$new;
$new after $endpoint
?? (last)
!! $new
}
!! $cmp > 0
?? {
my $new := .pred;
last if $_ before $endpoint;
$new;
$_ before $endpoint
?? (last)
!! .pred
}
!! { $_ }
}
Expand Down Expand Up @@ -132,17 +133,18 @@ class Rakudo::SEQUENCE {
$stop = 1 if $a gt $endpoint;
&producer = {
my $new := .succ;
last if $new gt $endpoint
or $new.chars > $endpoint.chars;
$new;
$new gt $endpoint || $new.chars > $endpoint.chars
?? (last)
!! $new
}
}
else {
$stop = 1 if $a lt $endpoint;
&producer = {
my $new := .pred;
last if $new lt $endpoint;
$new;
$new lt $endpoint
?? (last)
!! $new
}
}
}
Expand All @@ -167,16 +169,18 @@ class Rakudo::SEQUENCE {
$stop = 1 if $a > $endpoint;
&producer = {
my $new := $_ + $ab;
last if $new > $endpoint;
$new;
$new > $endpoint
?? (last)
!! $new
}
}
else {
$stop = 1 if $a < $endpoint;
&producer = {
my $new := $_ + $ab;
last if $new < $endpoint;
$new;
$new < $endpoint
?? (last)
!! $new
}
}
}
Expand Down Expand Up @@ -207,26 +211,29 @@ class Rakudo::SEQUENCE {
$stop = 1 if $a > $endpoint;
&producer = {
my $new := $_ * $ab;
last if $new > $endpoint;
$new;
$new > $endpoint
?? (last)
!! $new
}
}
else {
$stop = 1 if $a < $endpoint;
&producer = {
my $new := $_ * $ab;
last if $new < $endpoint;
$new;
$new < $endpoint
?? (last)
!! $new
}
}
}
else {
&producer = {
my $new := $_ * $ab;
my $absend := $endpoint.abs;
last if sign( .abs - $absend)
== -sign($new.abs - $absend);
$new;
sign(.abs - $absend)
== -sign($new.abs - $absend)
?? (last)
!! $new
}
}
}
Expand All @@ -253,16 +260,18 @@ class Rakudo::SEQUENCE {
$stop = 1 if $a > $endpoint;
&producer = {
my $new := $_ + $ab;
last if $new > $endpoint;
$new;
$new > $endpoint
?? (last)
!! $new
}
}
else {
$stop = 1 if $a < $endpoint;
&producer = {
my $new := $_ + $ab;
last if $new < $endpoint;
$new;
$new < $endpoint
?? (last)
!! $new
}
}
}
Expand All @@ -286,15 +295,17 @@ class Rakudo::SEQUENCE {
if $a < $endpoint {
&producer = {
my $new := .succ;
last if $new > $endpoint;
$new;
$new > $endpoint
?? (last)
!! $new
}
}
else {
&producer = {
my $new := .pred;
last if $new < $endpoint;
$new;
$new < $endpoint
?? (last)
!! $new
}
}
}
Expand Down

0 comments on commit cf6177e

Please sign in to comment.