Skip to content

Commit

Permalink
Add .append(IterationBuffer) methods to ReificationTargets
Browse files Browse the repository at this point in the history
So that we have a better change of .append working in iterators.
  • Loading branch information
lizmat committed Mar 18, 2018
1 parent 16daf02 commit 7d978fb
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/core/Array.pm6
Expand Up @@ -32,6 +32,22 @@ my class Array { # declared in BOOTSTRAP
nqp::push($!target,
nqp::assign(nqp::p6scalarfromdesc($!descriptor), value));
}

method append(IterationBuffer:D $buffer) {
nqp::if(
(my int $elems = nqp::elems($buffer)),
nqp::stmts(
(my int $i = -1),
nqp::while(
nqp::islt_i(($i = nqp::add_i($i,1)),$elems),
nqp::push($!target,nqp::assign(
nqp::p6scalarfromdesc($!descriptor),
nqp::atpos($buffer,$i)
))
)
)
)
}
}

my class ListReificationTarget {
Expand All @@ -45,6 +61,10 @@ my class Array { # declared in BOOTSTRAP
nqp::push($!target,
nqp::decont(value));
}

method append(IterationBuffer:D \buffer) {
nqp::splice($!target,buffer,nqp::elems($!target),0)
}
}

multi method clone(Array:D:) {
Expand Down

0 comments on commit 7d978fb

Please sign in to comment.