Skip to content

Commit

Permalink
Add Buf/Blob.STORE candidates for non-iterables
Browse files Browse the repository at this point in the history
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 84ed854
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/core/Buf.pm6
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 84ed854

Please sign in to comment.