Created
June 20, 2011 22:32
-
-
Save anonymous/1036768 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/core/ListIter.pm b/src/core/ListIter.pm | |
index 4eea79b..b8a5316 100644 | |
--- a/src/core/ListIter.pm | |
+++ b/src/core/ListIter.pm | |
@@ -12,32 +12,38 @@ my class ListIter { | |
my $pos = $!list.gimme(0) if $!list.defined; | |
my $flattens = $!list.defined && $!list.flattens; | |
my $eager = Whatever.ACCEPTS($n); | |
- while $!rest && ($eager || $n > 0) { | |
- $x := pir::set__PQi($!rest, 0); | |
+ my $rest_pos = 0; | |
+ while pir::islt__III($rest_pos, pir::elements($!rest)) | |
+ && ($eager || $n > 0) { | |
+ $x := pir::set__PQi($!rest, $rest_pos); | |
if pir::not__II(pir::is_container__IP($x)) && $x.defined | |
&& Iterable.ACCEPTS($x) { | |
last if $eager && $x.infinite; | |
pir::splice__vPPii( | |
$!rest, | |
pir__perl6_unbox_rpa__PP($x.iterator.reify($n)), | |
- 0, 1); | |
+ $rest_pos, 1); | |
} | |
elsif $flattens && pir::not__II(pir::is_container__IP($x)) | |
&& $x.defined && Parcel.ACCEPTS($x) { | |
pir::splice__vPPii( | |
$!rest, | |
pir__perl6_unbox_rpa__PP($x), | |
- 0, 1); | |
+ $rest_pos, 1); | |
} | |
- elsif Nil.ACCEPTS($x) { pir::shift__PP($!rest) } | |
+ elsif Nil.ACCEPTS($x) { $rest_pos++; } | |
else { | |
- pir::shift__PP($!rest); | |
+ $rest_pos++; | |
$x := $!list.STORE_AT_POS($pos, $x) if $!list.defined; | |
pir::push__vPP($rpa, $x); | |
$eager or $n = $n - 1; | |
$pos = $pos + 1; | |
} | |
} | |
+ if $rest_pos > 0 { | |
+ pir::splice__0PPii($!rest, pir::new__Ps('ResizablePMCArray'), | |
+ 0, $rest_pos); | |
+ } | |
pir::push__vPP( $rpa, | |
pir::setattribute__3PPsP(self, ListIter, '$!nextiter', | |
pir::perl6_iter_from_rpa__PPPP($!rest, $!list))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment