Skip to content

Commit

Permalink
Just go ahead and pass an Array to ConsIter -- makes the code a bit c…
Browse files Browse the repository at this point in the history
…leaner, fixes a bug, and doesn't seem to negatively impact the speed of things too much.
  • Loading branch information
colomon committed Jul 31, 2010
1 parent 685c1e7 commit 9b6189d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/core/Range.pm
Expand Up @@ -105,13 +105,13 @@ class Range is Iterable does Positional {
}

class ConsIter is Iterator {
has $!value-parcel;
has @!values;
has $!nextIter;

method infinite() { $!nextIter ~~ EMPTY ?? False !! $!nextIter.infinite; }

method reify() {
&infix:<,>(|$!value-parcel, $!nextIter);
&infix:<,>(|@!values, $!nextIter);
}
}

Expand All @@ -126,23 +126,28 @@ class Range is Iterable does Positional {
if $.min ~~ Int && $.max ~~ Int {
my $end = $.max;
$end .= pred if $.excludes_max;
return EMPTY if $start > $end;

if $start > $end {
return RangeIter.new( :value( EMPTY ),
:max($.max),
:excludes_max($.excludes_max));
}

my $mod = ($end - $start + 1) % 4;
if $mod == 0 {
FiniteIntRangeQuadIter.new(:value($start), :max($end));
} else {
my $parcel := pir::new__Ps('Parcel');
my @values;
my $i;
loop ($i = 0; $i < $mod; $i++) {
pir::push($parcel, $start + $i);
@values.push: $start + $i;
}

my $next-iter = $start + $mod < $end
?? FiniteIntRangeQuadIter.new(:value($start + $mod),
:max($end))
!! EMPTY;
ConsIter.new(:value-parcel($parcel),
ConsIter.new(:values(@values),
:nextIter($next-iter));
}
} else {
Expand Down

0 comments on commit 9b6189d

Please sign in to comment.