Skip to content

Commit

Permalink
Add support for native slice assignment from native
Browse files Browse the repository at this point in the history
Now that slices on native arrays return arrays of the same native
type, it makes sense to optimize assigning those values to a native
array.  This commit makes @A[1,2,3] = @b where @A and @b are of the
same native type, 26x as fast.  And makes it 18x as fast if the
receiving array is a native shaped array.
  • Loading branch information
lizmat committed Dec 6, 2020
1 parent 8eb9db3 commit a76e2b6
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 15 deletions.
114 changes: 102 additions & 12 deletions src/core.c/native_array.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -3730,7 +3730,7 @@ multi sub postcircumfix:<[ ]>(array:D \SELF, Range:D \range ) is raw {
}

#- start of postcircumfix candidates of strarray -------------------------------
#- Generated on 2020-12-04T21:05:04+01:00 by tools/build/makeNATIVE_CANDIDATES.raku
#- Generated on 2020-12-06T17:43:17+01:00 by tools/build/makeNATIVE_CANDIDATES.raku
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE

multi sub postcircumfix:<[ ]>(
Expand Down Expand Up @@ -3852,12 +3852,12 @@ multi sub postcircumfix:<[ ]>(
multi sub postcircumfix:<[ ]>(
array::strarray:D \SELF, Iterable:D $pos
) is raw {
my $self := nqp::decont(SELF);
my $iterator := $pos.iterator;
my $self := nqp::decont(SELF);
my $indices := $pos.iterator;
my str @result;

nqp::until(
nqp::eqaddr((my $pulled := $iterator.pull-one),IterationEnd),
nqp::eqaddr((my $pulled := $indices.pull-one),IterationEnd),
nqp::if(
nqp::islt_i(
(my int $got = nqp::if(
Expand All @@ -3875,6 +3875,36 @@ multi sub postcircumfix:<[ ]>(
@result
}

multi sub postcircumfix:<[ ]>(
array::strarray:D \SELF, Iterable:D $pos, array::strarray:D $values
) is raw {
my $self := nqp::decont(SELF);
my $indices := $pos.iterator;
my int $i = -1;
my str @result;

nqp::until(
nqp::eqaddr((my $pulled := $indices.pull-one),IterationEnd),
nqp::if(
nqp::islt_i(
(my int $got = nqp::if(
nqp::istype($pulled,Callable),
$pulled(nqp::elems($self)),
$pulled.Int
)),
0
),
X::OutOfRange.new(:what<Index>, :$got, :range<0..^Inf>).throw,
nqp::push_s(
@result,
nqp::bindpos_s($self,$got,nqp::atpos_s($values,++$i))
)
)
);

@result
}

multi sub postcircumfix:<[ ]>(
array::strarray:D \SELF, Whatever
) {
Expand All @@ -3885,7 +3915,7 @@ multi sub postcircumfix:<[ ]>(
#- end of postcircumfix candidates of strarray ---------------------------------

#- start of postcircumfix candidates of numarray -------------------------------
#- Generated on 2020-12-04T21:05:04+01:00 by tools/build/makeNATIVE_CANDIDATES.raku
#- Generated on 2020-12-06T17:43:17+01:00 by tools/build/makeNATIVE_CANDIDATES.raku
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE

multi sub postcircumfix:<[ ]>(
Expand Down Expand Up @@ -4007,12 +4037,12 @@ multi sub postcircumfix:<[ ]>(
multi sub postcircumfix:<[ ]>(
array::numarray:D \SELF, Iterable:D $pos
) is raw {
my $self := nqp::decont(SELF);
my $iterator := $pos.iterator;
my $self := nqp::decont(SELF);
my $indices := $pos.iterator;
my num @result;

nqp::until(
nqp::eqaddr((my $pulled := $iterator.pull-one),IterationEnd),
nqp::eqaddr((my $pulled := $indices.pull-one),IterationEnd),
nqp::if(
nqp::islt_i(
(my int $got = nqp::if(
Expand All @@ -4030,6 +4060,36 @@ multi sub postcircumfix:<[ ]>(
@result
}

multi sub postcircumfix:<[ ]>(
array::numarray:D \SELF, Iterable:D $pos, array::numarray:D $values
) is raw {
my $self := nqp::decont(SELF);
my $indices := $pos.iterator;
my int $i = -1;
my num @result;

nqp::until(
nqp::eqaddr((my $pulled := $indices.pull-one),IterationEnd),
nqp::if(
nqp::islt_i(
(my int $got = nqp::if(
nqp::istype($pulled,Callable),
$pulled(nqp::elems($self)),
$pulled.Int
)),
0
),
X::OutOfRange.new(:what<Index>, :$got, :range<0..^Inf>).throw,
nqp::push_n(
@result,
nqp::bindpos_n($self,$got,nqp::atpos_n($values,++$i))
)
)
);

@result
}

multi sub postcircumfix:<[ ]>(
array::numarray:D \SELF, Whatever
) {
Expand All @@ -4040,7 +4100,7 @@ multi sub postcircumfix:<[ ]>(
#- end of postcircumfix candidates of numarray ---------------------------------

#- start of postcircumfix candidates of intarray -------------------------------
#- Generated on 2020-12-04T21:05:04+01:00 by tools/build/makeNATIVE_CANDIDATES.raku
#- Generated on 2020-12-06T17:43:17+01:00 by tools/build/makeNATIVE_CANDIDATES.raku
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE

multi sub postcircumfix:<[ ]>(
Expand Down Expand Up @@ -4162,12 +4222,12 @@ multi sub postcircumfix:<[ ]>(
multi sub postcircumfix:<[ ]>(
array::intarray:D \SELF, Iterable:D $pos
) is raw {
my $self := nqp::decont(SELF);
my $iterator := $pos.iterator;
my $self := nqp::decont(SELF);
my $indices := $pos.iterator;
my int @result;

nqp::until(
nqp::eqaddr((my $pulled := $iterator.pull-one),IterationEnd),
nqp::eqaddr((my $pulled := $indices.pull-one),IterationEnd),
nqp::if(
nqp::islt_i(
(my int $got = nqp::if(
Expand All @@ -4185,6 +4245,36 @@ multi sub postcircumfix:<[ ]>(
@result
}

multi sub postcircumfix:<[ ]>(
array::intarray:D \SELF, Iterable:D $pos, array::intarray:D $values
) is raw {
my $self := nqp::decont(SELF);
my $indices := $pos.iterator;
my int $i = -1;
my int @result;

nqp::until(
nqp::eqaddr((my $pulled := $indices.pull-one),IterationEnd),
nqp::if(
nqp::islt_i(
(my int $got = nqp::if(
nqp::istype($pulled,Callable),
$pulled(nqp::elems($self)),
$pulled.Int
)),
0
),
X::OutOfRange.new(:what<Index>, :$got, :range<0..^Inf>).throw,
nqp::push_i(
@result,
nqp::bindpos_i($self,$got,nqp::atpos_i($values,++$i))
)
)
);

@result
}

multi sub postcircumfix:<[ ]>(
array::intarray:D \SELF, Whatever
) {
Expand Down
36 changes: 33 additions & 3 deletions tools/build/makeNATIVE_CANDIDATES.raku
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ multi sub postcircumfix:<[ ]>(
multi sub postcircumfix:<[ ]>(
array::#type#array:D \SELF, Iterable:D $pos
) is raw {
my $self := nqp::decont(SELF);
my $iterator := $pos.iterator;
my $self := nqp::decont(SELF);
my $indices := $pos.iterator;
my #type# @result;
nqp::until(
nqp::eqaddr((my $pulled := $iterator.pull-one),IterationEnd),
nqp::eqaddr((my $pulled := $indices.pull-one),IterationEnd),
nqp::if(
nqp::islt_i(
(my int $got = nqp::if(
Expand All @@ -193,6 +193,36 @@ multi sub postcircumfix:<[ ]>(
@result
}
multi sub postcircumfix:<[ ]>(
array::#type#array:D \SELF, Iterable:D $pos, array::#type#array:D $values
) is raw {
my $self := nqp::decont(SELF);
my $indices := $pos.iterator;
my int $i = -1;
my #type# @result;
nqp::until(
nqp::eqaddr((my $pulled := $indices.pull-one),IterationEnd),
nqp::if(
nqp::islt_i(
(my int $got = nqp::if(
nqp::istype($pulled,Callable),
$pulled(nqp::elems($self)),
$pulled.Int
)),
0
),
X::OutOfRange.new(:what<Index>, :$got, :range<0..^Inf>).throw,
nqp::push_#postfix#(
@result,
nqp::bindpos_#postfix#($self,$got,nqp::atpos_#postfix#($values,++$i))
)
)
);
@result
}
multi sub postcircumfix:<[ ]>(
array::#type#array:D \SELF, Whatever
) {
Expand Down

0 comments on commit a76e2b6

Please sign in to comment.