Skip to content

Commit

Permalink
Implement Buf.push(@list-of-items)
Browse files Browse the repository at this point in the history
Using code and ideas stolen from src/core/native_array.pm
  • Loading branch information
hoelzro committed May 29, 2015
1 parent 5f91c78 commit f5a0520
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/core/Buf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,16 @@ my role Buf[::T = uint8] does Blob[T] is repr('VMArray') is array_type(T) {
nqp::bindpos_i(self,$pos,assignee)
}

method push(Buf:D: Mu $value) {
multi method push(Buf:D: Mu $value) {
nqp::push_i(self, $value);
}

multi method push(Buf:D: @values) {
my int $length = nqp::elems(self);
my @splicees := nqp::create(self);
nqp::push_i(@splicees, @values.shift) while @values;
nqp::splice(self, @splicees, $length, 0);
}
}

constant buf8 = Buf[uint8];
Expand Down

0 comments on commit f5a0520

Please sign in to comment.