Skip to content

Commit

Permalink
List.reverse now uses R:I.ReifiedListReverse
Browse files Browse the repository at this point in the history
This saves one (potentially large) IterationBuffer allocation, plus
a lot of needless work copying values over.
  • Loading branch information
lizmat committed Apr 30, 2020
1 parent 3ca3802 commit 270cc27
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions src/core.c/List.pm6
Expand Up @@ -1131,17 +1131,7 @@ my class List does Iterable does Positional { # declared in BOOTSTRAP
method reverse(List:D: --> Seq:D) is nodal {
self.is-lazy # reifies
?? Failure.new(X::Cannot::Lazy.new(:action<reverse>))
!! Seq.new: $!reified
?? nqp::stmts(
(my \src := nqp::clone(nqp::getattr(self,List,'$!reified'))),
(my \dst := nqp::create(src.WHAT)),
nqp::while(
nqp::elems(src),
nqp::push(dst,nqp::pop(src))
),
Rakudo::Iterator.ReifiedList(dst)
)
!! Rakudo::Iterator.Empty
!! Seq.new: Rakudo::Iterator.ReifiedListReverse(self)
}

method rotate(List:D: Int(Cool) $rotate = 1) is nodal {
Expand Down

0 comments on commit 270cc27

Please sign in to comment.