Skip to content

Commit

Permalink
Add native array candidates for infix:<cmp>
Browse files Browse the repository at this point in the history
This makes cmp-ing native arrays about 3.5x as fast (in the worst case
for native arrays that are identical).  Faster still for other cases.
  • Loading branch information
lizmat committed Jul 20, 2021
1 parent 39ba888 commit 76714ca
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
48 changes: 45 additions & 3 deletions src/core.c/native_array.pm6
Expand Up @@ -3732,7 +3732,7 @@ multi sub postcircumfix:<[ ]>(array:D \SELF, Range:D \range ) is raw {
}

#- start of postcircumfix candidates of strarray -------------------------------
#- Generated on 2021-06-11T22:50:48+02:00 by tools/build/makeNATIVE_CANDIDATES.raku
#- Generated on 2021-07-20T13:33:00+02:00 by tools/build/makeNATIVE_CANDIDATES.raku
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE

multi sub postcircumfix:<[ ]>(
Expand Down Expand Up @@ -3965,11 +3965,25 @@ multi sub postcircumfix:<[ ]>(
nqp::decont(SELF)
}

multi sub infix:<cmp>(array::strarray:D \a, array::strarray:D \b) {
my int $elems-a = nqp::elems(a);
my int $elems-b = nqp::elems(b);
my int $elems = nqp::islt_i($elems-a,$elems-b) ?? $elems-a !! $elems-b;

my int $i = -1;
nqp::until(
nqp::isge_i(($i = nqp::add_i($i,1)),$elems)
|| (my $res = nqp::cmp_s(nqp::atpos_s(a,$i),nqp::atpos_s(b,$i))),
nqp::null
);
ORDER($res || nqp::cmp_i($elems-a,$elems-b))
}

#- PLEASE DON'T CHANGE ANYTHING ABOVE THIS LINE
#- end of postcircumfix candidates of strarray ---------------------------------

#- start of postcircumfix candidates of numarray -------------------------------
#- Generated on 2021-06-11T22:50:48+02:00 by tools/build/makeNATIVE_CANDIDATES.raku
#- Generated on 2021-07-20T13:33:00+02:00 by tools/build/makeNATIVE_CANDIDATES.raku
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE

multi sub postcircumfix:<[ ]>(
Expand Down Expand Up @@ -4202,11 +4216,25 @@ multi sub postcircumfix:<[ ]>(
nqp::decont(SELF)
}

multi sub infix:<cmp>(array::numarray:D \a, array::numarray:D \b) {
my int $elems-a = nqp::elems(a);
my int $elems-b = nqp::elems(b);
my int $elems = nqp::islt_i($elems-a,$elems-b) ?? $elems-a !! $elems-b;

my int $i = -1;
nqp::until(
nqp::isge_i(($i = nqp::add_i($i,1)),$elems)
|| (my $res = nqp::cmp_n(nqp::atpos_n(a,$i),nqp::atpos_n(b,$i))),
nqp::null
);
ORDER($res || nqp::cmp_i($elems-a,$elems-b))
}

#- PLEASE DON'T CHANGE ANYTHING ABOVE THIS LINE
#- end of postcircumfix candidates of numarray ---------------------------------

#- start of postcircumfix candidates of intarray -------------------------------
#- Generated on 2021-06-11T22:50:48+02:00 by tools/build/makeNATIVE_CANDIDATES.raku
#- Generated on 2021-07-20T13:33:00+02:00 by tools/build/makeNATIVE_CANDIDATES.raku
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE

multi sub postcircumfix:<[ ]>(
Expand Down Expand Up @@ -4439,6 +4467,20 @@ multi sub postcircumfix:<[ ]>(
nqp::decont(SELF)
}

multi sub infix:<cmp>(array::intarray:D \a, array::intarray:D \b) {
my int $elems-a = nqp::elems(a);
my int $elems-b = nqp::elems(b);
my int $elems = nqp::islt_i($elems-a,$elems-b) ?? $elems-a !! $elems-b;

my int $i = -1;
nqp::until(
nqp::isge_i(($i = nqp::add_i($i,1)),$elems)
|| (my $res = nqp::cmp_i(nqp::atpos_i(a,$i),nqp::atpos_i(b,$i))),
nqp::null
);
ORDER($res || nqp::cmp_i($elems-a,$elems-b))
}

#- PLEASE DON'T CHANGE ANYTHING ABOVE THIS LINE
#- end of postcircumfix candidates of intarray ---------------------------------

Expand Down
14 changes: 14 additions & 0 deletions tools/build/makeNATIVE_CANDIDATES.raku
Expand Up @@ -282,6 +282,20 @@ multi sub postcircumfix:<[ ]>(
nqp::decont(SELF)
}
multi sub infix:<cmp>(array::#type#array:D \a, array::#type#array:D \b) {
my int $elems-a = nqp::elems(a);
my int $elems-b = nqp::elems(b);
my int $elems = nqp::islt_i($elems-a,$elems-b) ?? $elems-a !! $elems-b;
my int $i = -1;
nqp::until(
nqp::isge_i(($i = nqp::add_i($i,1)),$elems)
|| (my $res = nqp::cmp_#postfix#(nqp::atpos_#postfix#(a,$i),nqp::atpos_#postfix#(b,$i))),
nqp::null
);
ORDER($res || nqp::cmp_i($elems-a,$elems-b))
}
SOURCE
# we're done for this role
Expand Down

0 comments on commit 76714ca

Please sign in to comment.