Skip to content

Commit

Permalink
Make infix before / after about 40% faster
Browse files Browse the repository at this point in the history
By moving their definitions until *after* we know about the Order enum
and then use the same fast-path approach as with sorting.  Also slap
the return signature on the proto.
  • Loading branch information
lizmat committed Mar 6, 2021
1 parent b2ae599 commit 0ad991e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 0 additions & 8 deletions src/core.c/Any.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,6 @@ multi sub infix:<===>(\a, \b --> Bool:D) {
)
}

proto sub infix:<before>($?, $?, *%) is pure {*}
multi sub infix:<before>($? --> True) { }
multi sub infix:<before>(\a, \b --> Bool:D) { (a cmp b) < 0 }

proto sub infix:<after>($?, $?, *%) is pure {*}
multi sub infix:<after>($x? --> True) { }
multi sub infix:<after>(\a, \b --> Bool:D) { (a cmp b) > 0 }

proto sub prefix:<++>(Mu, *%) {*}
multi sub prefix:<++>(Mu:D $a is rw) { $a = $a.succ }
multi sub prefix:<++>(Mu:U $a is rw) { $a = 1 }
Expand Down
14 changes: 13 additions & 1 deletion src/core.c/Order.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sub ORDER(int $i --> Order) is implementation-detail {
!! Same
}

proto sub infix:<cmp>($, $, *%) is pure {*}
proto sub infix:<cmp>($, $, *% --> Order:D) is pure {*}
multi sub infix:<cmp>(\a, \b) {
nqp::eqaddr(nqp::decont(a), nqp::decont(b))
?? Same
Expand Down Expand Up @@ -75,4 +75,16 @@ multi sub infix:«<=>»(int $a, int $b) {
ORDER(nqp::cmp_i($a, $b))
}

proto sub infix:<before>($?, $?, *% --> Bool:D) is pure {*}
multi sub infix:<before>($? --> True) { }
multi sub infix:<before>(\a, \b) {
nqp::hllbool(nqp::eqaddr((a cmp b),Order::Less))
}

proto sub infix:<after>($?, $?, *% --> Bool:D) is pure {*}
multi sub infix:<after>($x? --> True) { }
multi sub infix:<after>(\a, \b) {
nqp::hllbool(nqp::eqaddr((a cmp b),Order::More))
}

# vim: expandtab shiftwidth=4

0 comments on commit 0ad991e

Please sign in to comment.