Skip to content

Commit

Permalink
Make Blob.join between 4% and 11% faster
Browse files Browse the repository at this point in the history
- presize the result array back to 0
- use push_s instead of bindpos_s
- use an nqp::while instead of a while
  • Loading branch information
lizmat committed May 23, 2020
1 parent 1464b35 commit 84ff64c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/core.c/Buf.pm6
Expand Up @@ -518,12 +518,13 @@ my role Blob[::T = uint8] does Positional[T] does Stringy is repr('VMArray') is

method join(Blob:D: $delim = '') {
my int $elems = nqp::elems(self);
my $list := nqp::setelems(nqp::list_s,$elems);
my int $i = -1;
my $list := nqp::setelems(nqp::setelems(nqp::list_s,$elems),0);

nqp::bindpos_s($list,$i,
nqp::tostr_I(nqp::p6box_i(nqp::atpos_i(self,$i))))
while nqp::islt_i(++$i,$elems);
nqp::while(
nqp::islt_i(($i = nqp::add_i($i,1)),$elems),
nqp::push_s($list,nqp::atpos_i(self,$i))
);

nqp::join($delim.Str,$list)
}
Expand Down

0 comments on commit 84ff64c

Please sign in to comment.