Skip to content

Commit

Permalink
Add a IterationBuffer.new(iterable) candidate
Browse files Browse the repository at this point in the history
To facilitate initializing iteration buffers.  Makes

    IterationBuffer.new(<a b c d e f g h i j>);

about 2x as fast as:

    my $b := IterationBuffer.new;
    $b.push($_) for <a b c d e f g h i j>;
    $b
  • Loading branch information
lizmat committed Oct 28, 2021
1 parent 4fece61 commit a8db54a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core.c/IterationBuffer.pm6
Expand Up @@ -11,6 +11,12 @@
# of Raku. Do NOT add any checks and validation to methods in here. They
# need to remain trivially inlinable for performance reasons.
my class IterationBuffer {

multi method new(IterationBuffer:U: Iterable:D \iterable) {
iterable.iterator.push-all(my \buffer := nqp::create(self));
buffer
}

method clear(IterationBuffer:D: --> Nil) {
nqp::setelems(self, 0)
}
Expand Down

0 comments on commit a8db54a

Please sign in to comment.