Skip to content
Permalink
Browse files

Streamline negating Rat / FatRat

- instead of creating new object using .new
- just clone the object and negate the numerator
- makes it about 3x as fast
  • Loading branch information...
lizmat committed Jan 2, 2019
1 parent e0cd1d9 commit d195e146230ec99d6cd61cfe9ed2edf6cf6b3ab0
Showing with 14 additions and 2 deletions.
  1. +14 −2 src/core/Rat.pm6
@@ -86,10 +86,22 @@ sub RAKUDO_INTERNAL_DIVIDE_NUMBERS_NO_NORMALIZE(\nu, \de, \t1, \t2) {
}

multi sub prefix:<->(Rat:D \a --> Rat:D) {
Rat.new(-a.numerator, a.denominator);
# Rat.new(-a.numerator, a.denominator);
nqp::p6bindattrinvres(
nqp::clone(nqp::decont(a)),
Rat,
'$!numerator',
nqp::neg_I(nqp::getattr(nqp::decont(a),Rat,'$!numerator'),Int)
)
}
multi sub prefix:<->(FatRat:D \a --> FatRat:D) {
FatRat.new(-a.numerator, a.denominator);
# FatRat.new(-a.numerator, a.denominator);
nqp::p6bindattrinvres(
nqp::clone(nqp::decont(a)),
FatRat,
'$!numerator',
nqp::neg_I(nqp::getattr(nqp::decont(a),FatRat,'$!numerator'),Int)
)
}

multi sub infix:<+>(Rational:D \a, Rational:D \b) {

0 comments on commit d195e14

Please sign in to comment.
You can’t perform that action at this time.