From 28c1fff3262c19af158b641aff28f2d40c22da37 Mon Sep 17 00:00:00 2001 From: pmichaud Date: Thu, 23 Jun 2011 14:31:14 -0500 Subject: [PATCH] Our aggregates can benefit from some Infinite wisdom again. --- src/core/Any.pm | 1 + src/core/Array.pm | 10 ++++++++++ src/core/List.pm | 3 +-- src/core/ListIter.pm | 3 ++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/core/Any.pm b/src/core/Any.pm index dd5fb1538a5..5371f6573c1 100644 --- a/src/core/Any.pm +++ b/src/core/Any.pm @@ -11,6 +11,7 @@ my class Any { method flat() { nqp::p6list(List, nqp::list(self), 1.Bool) } method list() { nqp::p6list(List, nqp::list(self), Mu) } method elems() { self.list.elems } + method infinite() { Mu } method join($separator = ' ') { my $list = (self,).flat.eager; diff --git a/src/core/Array.pm b/src/core/Array.pm index eb3c0d9fc27..091ceda2aab 100644 --- a/src/core/Array.pm +++ b/src/core/Array.pm @@ -16,6 +16,16 @@ class Array { !! self.WHAT.perl ~ '.new(' ~ self.map({.perl}).join(', ') ~ ')' } + method REIFY(Parcel \$parcel) { + my Mu $rpa := $parcel.RPA; + my Mu $iter := nqp::iterator($rpa); + my $i = 0; + while $iter { + nqp::bindpos($rpa, nqp::unbox_i($i++), my $v = nqp::shift($iter)); + } + pir::find_method__PPs(List, 'REIFY')(self, $parcel) + } + method STORE_AT_POS(\$pos, Mu $v is copy) { pir::find_method__PPs(List, 'STORE_AT_POS')(self, $pos, $v); } diff --git a/src/core/List.pm b/src/core/List.pm index ae2acc49475..c14808fbd5f 100644 --- a/src/core/List.pm +++ b/src/core/List.pm @@ -59,8 +59,7 @@ class List { } method infinite() { - self.gimme(*); - $!nextiter.defined + $!nextiter.defined && $!nextiter.infinite; } method iterator() { diff --git a/src/core/ListIter.pm b/src/core/ListIter.pm index b8e4a919f8c..d775ec4ef0a 100644 --- a/src/core/ListIter.pm +++ b/src/core/ListIter.pm @@ -25,6 +25,7 @@ my class ListIter { if $!rest && nqp::islt_i(nqp::elems($rpa), nqp::unbox_i($count)) { $x := nqp::shift($!rest); if nqp::isconcrete($x) { + last if $eager && $x.infinite; $x := $x.iterator.reify($count) if nqp::p6isa($x, Iterable); nqp::splice($!rest, nqp::getattr($x, Parcel, '$!storage'), 0, 0); @@ -51,7 +52,7 @@ my class ListIter { method infinite() { $!rest - ?? Iterable.ACCEPTS(nqp::atpos($!rest,0)) + ?? nqp::p6isa(nqp::atpos($!rest, 0), Iterable) && nqp::atpos($!rest,0).infinite || Mu !! 0.Bool