Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
We need to look into this deeper.
  • Loading branch information
lizmat committed Jun 22, 2019
1 parent 0b97626 commit 090f3f1
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 24 deletions.
8 changes: 0 additions & 8 deletions src/core/Iterator.pm6
Expand Up @@ -131,12 +131,4 @@ my role PredictiveIterator does Iterator {
method bool-only(--> Bool:D) { self.count-only.Bool }
}

# The CachedIterator role is a refinement of the PredictiveIterator role for
# those cases when all values have been generated already. It prevents the
# already generated values from being cached yet again for a Sequence.
my role CachedIterator does PredictiveIterator {
# The "cache" method should return a List of the already generated values.
method cache(--> List:D) { ... }
}

# vim: ft=perl6 expandtab sw=4
10 changes: 2 additions & 8 deletions src/core/Rakudo/Iterator.pm6
Expand Up @@ -2612,7 +2612,7 @@ class Rakudo::Iterator {
# Return an iterator for an Array that has been completely reified
# already. Returns a assignable container for elements don't exist
# before the end of the reified array.
my class ReifiedArrayIterator does CachedIterator {
my class ReifiedArrayIterator does PredictiveIterator {
has $!reified;
has $!descriptor;
has int $!i;
Expand Down Expand Up @@ -2701,9 +2701,6 @@ class Rakudo::Iterator {
- nqp::islt_i($!i,nqp::elems($!reified))
)
}
method cache(--> List:D) {
nqp::p6bindattrinvres(nqp::create(List),List,'$!reified',$!reified)
}
method sink-all(--> IterationEnd) { $!i = nqp::elems($!reified) }
}
method ReifiedArray(\array, Mu \descriptor) {
Expand All @@ -2713,7 +2710,7 @@ class Rakudo::Iterator {
# Return an iterator for a List that has been completely reified
# already. Returns an nqp::null for elements that don't exist
# before the end of the reified list.
my class ReifiedListIterator does CachedIterator {
my class ReifiedListIterator does Iterator {
has $!reified;
has int $!i;

Expand Down Expand Up @@ -2794,9 +2791,6 @@ class Rakudo::Iterator {
- nqp::islt_i($!i,nqp::elems($!reified))
)
}
method cache(--> List:D) {
nqp::p6bindattrinvres(nqp::create(List),List,'$!reified',$!reified)
}
method sink-all(--> IterationEnd) { $!i = nqp::elems($!reified) }
}
method ReifiedList(\list) {
Expand Down
8 changes: 1 addition & 7 deletions src/core/Seq.pm6
Expand Up @@ -19,13 +19,7 @@ my class Seq is Cool does Iterable does Sequence {
nqp::if(
nqp::isconcrete(my \iter = $!iter),
nqp::stmts(
($!iter := Iterator), # allow usage only once
nqp::if(
nqp::istype(iter,CachedIterator),
nqp::bindattr( # can set up cache now
self,::?CLASS,'$!list',nqp::decont(iter.cache)
)
),
($!iter := Iterator),
iter
),
nqp::if(
Expand Down
2 changes: 1 addition & 1 deletion src/core/Sequence.pm6
Expand Up @@ -29,7 +29,7 @@ my role PositionalBindFailover {
)
}
multi method list(::?CLASS:D:) {
self.cache
List.from-iterator(self.iterator)
}

method iterator() { ... }
Expand Down

0 comments on commit 090f3f1

Please sign in to comment.