Skip to content
Permalink
Browse files

Add Buf/Blob.STORE candidates for non-iterables

For some reason we cannot make things like CArray an Iterable without
breaking a lot of things (like R#2687).  This fixes R#2681 the hard way.
If the native types are the same, this could be sped up quite a bit, but
I don't see a quick way to introspect that and fast-path that.
  • Loading branch information...
lizmat committed Feb 12, 2019
1 parent 30fc514 commit 84ed8548f97ff66c1ad80d0dc9dfe56d3dbd0081
Showing with 11 additions and 0 deletions.
  1. +11 −0 src/core/Buf.pm6
@@ -63,6 +63,12 @@ my role Blob[::T = uint8] does Positional[T] does Stringy is repr('VMArray') is
!! self!push-list("initializ",self,iterable)
!! X::Assignment::RO.new(:value(self)).throw
}
multi method STORE(Blob:D: Any:D \non-iterable, :$INITIALIZE) {
X::Assignment::RO.new(:value(self)).throw unless $INITIALIZE;
my int $elems = non-iterable.elems;
self.ASSIGN-POS($_, non-iterable.AT-POS($_)) for ^$elems;
self
}

proto method allocate(|) {*}
multi method allocate(Blob:U: Int:D $elements) {
@@ -711,6 +717,11 @@ my role Buf[::T = uint8] does Blob[T] is repr('VMArray') is array_type(T) {
?? X::Cannot::Lazy.new(:action<store>,:what(self.^name)).throw
!! self!push-list("initializ",nqp::setelems(self,0),iterable);
}
multi method STORE(Buf:D: Any:D \non-iterable) {
my int $elems = non-iterable.elems;
self.ASSIGN-POS($_, non-iterable.AT-POS($_)) for ^$elems;
nqp::setelems(self,$elems)
}

#?if moar
# for simplicity's sake, these are not multis

0 comments on commit 84ed854

Please sign in to comment.
You can’t perform that action at this time.