Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improve performance of Buf creation and listification.
  • Loading branch information
jnthn committed Oct 23, 2011
1 parent 977b33b commit 7ac6d1e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/core/Buf.pm
Expand Up @@ -14,15 +14,18 @@ class Buf does Positional {
$new;
}
method !set_codes(*@codes) {
pir::set__vPI($!buffer, nqp::unbox_i(@codes.elems));
for @codes.keys -> $k {
pir::set__1Qii($!buffer, nqp::unbox_i($k), nqp::unbox_i(@codes[$k]));
my int $bytes = @codes.elems;
pir::set__vPI($!buffer, $bytes);
my int $i = 0;
while $i < $bytes {
nqp::bindpos_i($!buffer, $i, nqp::unbox_i(@codes[$i]));
$i = $i + 1;
}
self;
}

method at_pos(Buf:D: Int:D $idx) {
nqp::p6box_i(pir::set__IQi($!buffer, nqp::unbox_i($idx)));
nqp::p6box_i(nqp::atpos_i($!buffer, nqp::unbox_i($idx)));
}

method elems(Buf:D:) {
Expand All @@ -36,8 +39,11 @@ class Buf does Positional {

method list() {
my @l;
for ^nqp::p6box_i(nqp::elems($!buffer)) -> $k {
@l.push: self.at_pos($k);
my int $bytes = nqp::elems($!buffer);
my int $i = 0;
while $i < $bytes {
@l.push: nqp::p6box_i(nqp::atpos_i($!buffer, $i));
$i = $i + 1;
}
@l;
}
Expand Down

0 comments on commit 7ac6d1e

Please sign in to comment.