Skip to content

Commit

Permalink
Make Object:D cmp Object:D 2x as fast
Browse files Browse the repository at this point in the history
The basic version was testing for Inf/-Inf.  By adding candidates
for Real/Any and Any/Real and moving the test for Inf/-Inf in there,
we no longer need to do that in the basic version.  Also added a
very cheap test for identity, so comparing with itself should be a
lot faster as well.

Also nqpified the ORDER helper sub, just in case it would make a
difference.
  • Loading branch information
lizmat committed Mar 29, 2016
1 parent 27dca5d commit a424f07
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/core/Order.pm
Expand Up @@ -2,16 +2,36 @@
my enum Order (:Less(-1), :Same(0), :More(1));

sub ORDER(int $i) {
$i == 0 ?? Same !! $i < 0 ?? Less !! More
nqp::iseq_i($i,0) ?? Same !! nqp::islt_i($i,0) ?? Less !! More
}

proto sub infix:<cmp>(Mu $, Mu $) is pure { * }
multi sub infix:<cmp>(\a, \b) {
return Order::Less if a === -Inf || b === Inf;
return Order::More if a === Inf || b === -Inf;
a.Stringy cmp b.Stringy
nqp::eqaddr(a,b)
?? Same
!! a.Stringy cmp b.Stringy
}
multi sub infix:<cmp>(Real:D \a, \b) {
a === -Inf
?? Less
!! a === Inf
?? More
!! a.Stringy cmp b.Stringy
}
multi sub infix:<cmp>(\a, Real:D \b) {
b === Inf
?? Less
!! b === -Inf
?? More
!! a.Stringy cmp b.Stringy
}
multi sub infix:<cmp>(Real:D \a, Real:D \b) {
a === -Inf || b === Inf
?? Less
!! a === Inf || b === -Inf
?? More
!! a.Bridge cmp b.Bridge
}
multi sub infix:<cmp>(Real \a, Real \b) { a.Bridge cmp b.Bridge }
multi sub infix:<cmp>(Int:D \a, Int:D \b) {
ORDER(nqp::cmp_I(nqp::decont(a), nqp::decont(b)))
}
Expand Down

0 comments on commit a424f07

Please sign in to comment.