Skip to content

Commit

Permalink
Streamline ArrayReificationTarget a bit
Browse files Browse the repository at this point in the history
- don't iterate over appending buffer, but shift out of it
- lose some nqp::stmts for readability
  • Loading branch information
lizmat committed May 14, 2020
1 parent 2aac854 commit b50fd8b
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions src/core.c/Array.pm6
Expand Up @@ -20,31 +20,21 @@ my class Array { # declared in BOOTSTRAP
has $!descriptor;

method new(\target, Mu \descriptor) {
nqp::stmts(
nqp::bindattr((my \rt = nqp::create(self)),
self,'$!target',target),
nqp::p6bindattrinvres(rt,
self,'$!descriptor',descriptor)
)
nqp::bindattr((my \rt = nqp::create(self)),self,'$!target',target);
nqp::p6bindattrinvres(rt,self,'$!descriptor',descriptor)
}

method push(Mu \value --> Nil) {
nqp::push($!target, nqp::p6scalarwithvalue($!descriptor, value));
}

method append(IterationBuffer:D $buffer --> Nil) {
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::p6scalarwithvalue($!descriptor,nqp::atpos($buffer,$i))
)
)
method append(IterationBuffer:D \buffer --> Nil) {
nqp::while(
nqp::elems(buffer),
nqp::push($!target,
nqp::p6scalarwithvalue($!descriptor,nqp::shift(buffer))
)
)
);
}
}

Expand All @@ -56,8 +46,7 @@ my class Array { # declared in BOOTSTRAP
}

method push(Mu \value --> Nil) {
nqp::push($!target,
nqp::decont(value));
nqp::push($!target,nqp::decont(value));
}

method append(IterationBuffer:D \buffer --> Nil) {
Expand Down

0 comments on commit b50fd8b

Please sign in to comment.